Instance Method

removeFileAtPath:handler:

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

Declaration

- (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 fileManager:willProcessPath: and fileManager:shouldProceedAfterError:. You can specify nil for handler; if you do so and an error occurs, the deletion stops and the method automatically returns NO.

Return Value

YES if the removal operation is successful. If the operation is not successful, but the handler method fileManager:shouldProceedAfterError: returns YES, also returns YES; otherwise returns NO.

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 removeItemAtURL:error: instead.

See Also

Related Symbols

- fileManager:willProcessPath:

An NSFileManager object sends this message to a handler immediately before attempting to move, copy, rename, or delete, or before attempting to link to a given path.

- fileManager:shouldProceedAfterError:

An NSFileManager object sends this message to its handler for each error it encounters when copying, moving, removing, or linking files or directories.

- linkItemAtURL:toURL:error:

Creates a hard link between the items at the specified URLs.

- moveItemAtPath:toPath:error:

Moves the file or directory at the specified path to a new location synchronously.

- copyItemAtPath:toPath:error:

Copies the item at the specified path to a new location synchronously.

- removeItemAtPath:error:

Removes the file or directory at the specified path.