---
title: "removeFileAtPath:handler:"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/nsfilemanager/removefileatpath:handler:"
---

# removeFileAtPath:handler:

Deletes the file, link, or directory (including, recursively, all subdirectories, files, and links in the directory) identified by a given path.

## Declaration

```occ
- (BOOL) removeFileAtPath:(NSString *) path handler:(id) handler;
```

## Parameters

- `path`: The path of a file, link, or directory to delete. The value must not be “.” or “..”.
- `handler`: An object that responds to the callback messages doc://com.apple.documentation/documentation/ObjectiveC/NSObject-swift.class/fileManager(_:willProcessPath:) and doc://com.apple.documentation/documentation/ObjectiveC/NSObject-swift.class/fileManager(_:shouldProceedAfterError:). You can specify nil for handler; if you do so and an error occurs, the deletion stops and the method automatically returns doc://com.apple.documentation/documentation/Swift/false.

## Return Value

Return Value true if the removal operation is successful. If the operation is not successful, but the handler method fileManager(_:shouldProceedAfterError:) returns true, also returns true; otherwise returns false.

## Discussion

Discussion This callback mechanism provided by handler is similar to delegation. NSFileManager sends fileManager(_:willProcessPath:) when it begins a copy, move, remove, or link operation. It sends fileManager(_:shouldProceedAfterError:) when it encounters any error in processing. Since the removal of directory contents is so thorough and final, be careful when using this method. If you specify “.” or “..” for path an NSInvalidArgumentException exception is raised. This method does not traverse symbolic links. Special Considerations Because this method does not return error information, it has been deprecated as of OS X v10.5. Use removeItem(at:) instead.

## See Also

### Related Documentation

- [linkItem(at:to:)](foundation/filemanager/linkitem(at:to:).md)
- [moveItem(atPath:toPath:)](foundation/filemanager/moveitem(atpath:topath:).md)
- [copyItem(atPath:toPath:)](foundation/filemanager/copyitem(atpath:topath:).md)
- [removeItem(atPath:)](foundation/filemanager/removeitem(atpath:).md)

### Deprecated Methods

- [copyPath:toPath:handler:](foundation/nsfilemanager/copypath:topath:handler:.md)
- [movePath:toPath:handler:](foundation/nsfilemanager/movepath:topath:handler:.md)
- [changeFileAttributes(_:atPath:)](foundation/filemanager/changefileattributes(_:atpath:).md)
- [fileAttributes(atPath:traverseLink:)](foundation/filemanager/fileattributes(atpath:traverselink:).md)
- [fileSystemAttributes(atPath:)](foundation/filemanager/filesystemattributes(atpath:).md)
- [directoryContents(atPath:)](foundation/filemanager/directorycontents(atpath:).md)
- [createDirectory(atPath:attributes:)](foundation/filemanager/createdirectory(atpath:attributes:).md)
- [createSymbolicLink(atPath:pathContent:)](foundation/filemanager/createsymboliclink(atpath:pathcontent:).md)
- [pathContentOfSymbolicLink(atPath:)](foundation/filemanager/pathcontentofsymboliclink(atpath:).md)
- [linkPath:toPath:handler:](foundation/nsfilemanager/linkpath:topath:handler:.md)
- [fileManager(_:shouldProceedAfterError:)](objectivec/nsobject-swift.class/filemanager(_:shouldproceedaftererror:).md)
- [fileManager(_:willProcessPath:)](objectivec/nsobject-swift.class/filemanager(_:willprocesspath:).md)
