NSFileManagerDelegate Protocol Reference

Conforms to
Framework
/System/Library/Frameworks/Foundation.framework
Availability
Available in OS X v10.7 and later.
Companion guide
Low-Level File Management Programming Topics
Declared in
NSFileManager.h

Overview

The NSFileManagerDelegate protocol defines optional methods for managing operations involving the copying, moving, linking, or removal of files and directories. When you use an NSFileManager object to initiate a copy, move, link, or remove operation, the file manager asks its delegate whether the operation should begin at all and whether it should proceed when an error occurs.

The methods of this protocol accept either NSURL or NSString objects. The file manager always prefers methods that take an NSURL object over those that take an NSString object.

You should associate your delegate with a unique instance of the NSFileManager class, as opposed to the shared instance.

Tasks

Moving an Item

Copying an Item

Removing an Item

Linking an Item

Instance Methods

fileManager:shouldCopyItemAtPath:toPath:

Asks the delegate if the file manager should copy the specified item to the new path.

- (BOOL)fileManager:(NSFileManager *)fileManager shouldCopyItemAtPath:(NSString *)srcPath toPath:(NSString *)dstPath
Parameters
fileManager

The file manager object that is attempting to copy the file or directory.

srcPath

The path to the file or directory that the file manager wants to copy.

dstPath

The new path for the copied file or directory.

Return Value

YES if the item should be copied or NO if the file manager should stop copying items associated with the current operation. If you do not implement this method, the file manager assumes a response of YES.

Discussion

This method is called once for each item that needs to be copied. Thus, for a directory, this method is called once for the directory and once for each item in the directory.

This method performs the same task as the fileManager:shouldCopyItemAtURL:toURL: method, which is preferred over this method in OS X v10.6 and later.

Availability
  • Available in OS X v10.5 and later.
  • Available as part of an informal protocol prior to OS X v10.7.
Declared In
NSFileManager.h

fileManager:shouldCopyItemAtURL:toURL:

Asks the delegate if the file manager should copy the specified item to the new URL.

- (BOOL)fileManager:(NSFileManager *)fileManager shouldCopyItemAtURL:(NSURL *)srcURL toURL:(NSURL *)dstURL
Parameters
fileManager

The file manager object that is attempting to copy the file or directory.

srcURL

The URL of the file or directory that the file manager wants to copy.

dstURL

The URL specifying the location for the copied file or directory.

Return Value

YES if the item should be copied or NO if the file manager should stop copying items associated with the current operation. If you do not implement this method, the file manager assumes a response of YES.

Discussion

This method is called once for each item that needs to be copied. Thus, for a directory, this method is called once for the directory and once for each item in the directory.

This method performs the same task as the fileManager:shouldCopyItemAtPath:toPath: method and is preferred over that method in OS X v10.6 and later.

Availability
  • Available in OS X v10.6 and later.
  • Available as part of an informal protocol prior to OS X v10.7.
Declared In
NSFileManager.h

fileManager:shouldLinkItemAtPath:toPath:

Asks the delegate if a hard link should be created between the items at the two paths.

- (BOOL)fileManager:(NSFileManager *)fileManager shouldLinkItemAtPath:(NSString *)srcPath toPath:(NSString *)dstPath
Parameters
fileManager

The file manager object that is attempting to create the link.

srcPath

The path or a file or directory that fileManager is about to attempt to link.

dstPath

The path or a file or directory to which fileManager is about to attempt to link.

Return Value

YES if the operation should proceed, otherwise NO.

Discussion

If the item specified by destURL is a directory, returning NO prevents links from being created to both the directory and its children.

This method performs the same task as the fileManager:shouldLinkItemAtURL:toURL: method, which is preferred over this method in OS X v10.6 and later.

Availability
  • Available in OS X v10.5 and later.
  • Available as part of an informal protocol prior to OS X v10.7.
Declared In
NSFileManager.h

fileManager:shouldLinkItemAtURL:toURL:

Asks the delegate if a hard link should be created between the items at the two URLs.

- (BOOL)fileManager:(NSFileManager *)fileManager shouldLinkItemAtURL:(NSURL *)srcURL toURL:(NSURL *)dstURL
Parameters
fileManager

The file manager object that is attempting to create the link.

srcURL

The URL identifying the new hard link to be created.

dstURL

The URL identifying the destination of the link.

Return Value

YES if the link should be created or NO if it should not be created.

Discussion

If the item specified by destURL is a directory, returning NO prevents links from being created to both the directory and its children.

This method performs the same task as the fileManager:shouldLinkItemAtPath:toPath: method and is preferred over that method in OS X v10.6 and later.

Availability
  • Available in OS X v10.6 and later.
  • Available as part of an informal protocol prior to OS X v10.7.
Declared In
NSFileManager.h

fileManager:shouldMoveItemAtPath:toPath:

Asks the delegate if the file manager should move the specified item to the new path.

- (BOOL)fileManager:(NSFileManager *)fileManager shouldMoveItemAtPath:(NSString *)srcPath toPath:(NSString *)dstPath
Parameters
fileManager

The file manager object that is attempting to move the file or directory.

srcPath

The path to the file or directory that the file manager wants to move.

dstPath

The new path for the file or directory.

Return Value

YES if the operation should proceed, otherwise NO. If you do not implement this method, the file manager assumes a response of YES.

Discussion

This method is called only once for the item being moved, regardless of whether the item is a file, directory, or symbolic link.

This method performs the same task as the fileManager:shouldMoveItemAtURL:toURL: method, which is preferred over this method in OS X v10.6 and later.

Availability
  • Available in OS X v10.5 and later.
  • Available as part of an informal protocol prior to OS X v10.7.
Declared In
NSFileManager.h

fileManager:shouldMoveItemAtURL:toURL:

Asks the delegate if the file manager should move the specified item to the new URL.

- (BOOL)fileManager:(NSFileManager *)fileManager shouldMoveItemAtURL:(NSURL *)srcURL toURL:(NSURL *)dstURL
Parameters
fileManager

The file manager object that is attempting to move the file or directory.

srcURL

The URL of the file or directory that the file manager wants to move.

dstURL

The URL specifying the new location for the file or directory.

Return Value

YES if the item should be moved or NO if it should not be moved. If you do not implement this method, the file manager assumes a response of YES.

Discussion

This method is called only once for the item being moved, regardless of whether the item is a file, directory, or symbolic link.

This method performs the same task as the fileManager:shouldMoveItemAtPath:toPath: method and is preferred over that method in OS X v10.6 and later.

Availability
  • Available in OS X v10.6 and later.
  • Available as part of an informal protocol prior to OS X v10.7.
Declared In
NSFileManager.h

fileManager:shouldProceedAfterError:copyingItemAtPath:toPath:

Asks the delegate if the move operation should continue after an error occurs while copying the item at the specified path.

- (BOOL)fileManager:(NSFileManager *)fileManager shouldProceedAfterError:(NSError *)error copyingItemAtPath:(NSString *)srcPath toPath:(NSString *)dstPath
Parameters
fileManager

The NSFileManager object that sent this message.

error

The error that occurred during the attempt to copy.

srcPath

The path or a file or directory that fileManager is attempting to copy.

dstPath

The path or a file or directory to which fileManager is attempting to copy.

Return Value

YES if the operation should proceed or NO if it should be aborted. If you do not implement this method, the file manager assumes a response of NO.

Discussion

The file manager calls this method when there is a problem copying the item to the specified location. If you return YES, the file manager continues copying any other items and ignores the error.

This method performs the same task as the fileManager:shouldProceedAfterError:copyingItemAtURL:toURL: method, which is preferred over this method in OS X v10.6 and later.

Availability
  • Available in OS X v10.5 and later.
  • Available as part of an informal protocol prior to OS X v10.7.
Declared In
NSFileManager.h

fileManager:shouldProceedAfterError:copyingItemAtURL:toURL:

Asks the delegate if the move operation should continue after an error occurs while copying the item at the specified URL.

- (BOOL)fileManager:(NSFileManager *)fileManager shouldProceedAfterError:(NSError *)error copyingItemAtURL:(NSURL *)srcURL toURL:(NSURL *)dstURL
Parameters
fileManager

The file manager object that attempted to copy the item.

error

The error that occurred during the attempt to copy.

srcURL

The URL or a file or directory that fileManager is attempting to copy.

dstURL

The URL or a file or directory to which fileManager is attempting to copy.

Return Value

YES if the operation should proceed or NO if it should be aborted. If you do not implement this method, the file manager assumes a response of NO.

Discussion

The file manager calls this method when there is a problem copying the item to the specified location. If you return YES, the file manager continues copying any other items and ignores the error.

This method performs the same task as the fileManager:shouldProceedAfterError:copyingItemAtPath:toPath: method and is preferred over that method in OS X v10.6 and later.

Availability
  • Available in OS X v10.6 and later.
  • Available as part of an informal protocol prior to OS X v10.7.
Declared In
NSFileManager.h

fileManager:shouldProceedAfterError:linkingItemAtPath:toPath:

Asks the delegate if the operation should continue after an error occurs while linking to the item at the specified path.

- (BOOL)fileManager:(NSFileManager *)fileManager shouldProceedAfterError:(NSError *)error linkingItemAtPath:(NSString *)srcPath toPath:(NSString *)dstPath
Parameters
fileManager

The file manager object that attempted to create the link.

error

The error that occurred during the link attempt.

srcPath

The path to the attempted link location.

dstPath

The path to the file or directory that was the destination of the hard link.

Return Value

YES if the operation should proceed or NO if it should be aborted. If you do not implement this method, the file manager assumes a response of NO.

Discussion

The file manager calls this method when there is a problem creating a hard link to the item at the specified location. If you return YES, the file manager continues creating any other links associated with the current operation and ignores the error.

This method performs the same task as the fileManager:shouldProceedAfterError:linkingItemAtURL:toURL: method, which is preferred over this method in OS X v10.6 and later.

Availability
  • Available in OS X v10.5 and later.
  • Available as part of an informal protocol prior to OS X v10.7.
Declared In
NSFileManager.h

fileManager:shouldProceedAfterError:linkingItemAtURL:toURL:

Asks the delegate if the operation should continue after an error occurs while linking to the item at the specified URL.

- (BOOL)fileManager:(NSFileManager *)fileManager shouldProceedAfterError:(NSError *)error linkingItemAtURL:(NSURL *)srcURL toURL:(NSURL *)dstURL
Parameters
fileManager

The file manager object that attempted to create the link.

error

The error that occurred during the link attempt.

srcURL

The URL of the attempted link location.

dstURL

The URL of the file or directory that was the destination of the hard link.

Return Value

YES if the operation should proceed or NO if it should be aborted. If you do not implement this method, the file manager assumes a response of NO.

Discussion

The file manager calls this method when there is a problem creating a hard link to the item at the specified location. If you return YES, the file manager continues creating any other links associated with the current operation and ignores the error.

This method performs the same task as the fileManager:shouldProceedAfterError:linkingItemAtPath:toPath: method and is preferred over that method in OS X v10.6 and later.

Availability
  • Available in OS X v10.6 and later.
  • Available as part of an informal protocol prior to OS X v10.7.
Declared In
NSFileManager.h

fileManager:shouldProceedAfterError:movingItemAtPath:toPath:

Asks the delegate if the move operation should continue after an error occurs while moving the item at the specified path.

- (BOOL)fileManager:(NSFileManager *)fileManager shouldProceedAfterError:(NSError *)error movingItemAtPath:(NSString *)srcPath toPath:(NSString *)dstPath
Parameters
fileManager

The file manager object that attempted to move the item.

error

The error that occurred while trying to move the item in srcPath.

srcPath

The path of the file or directory that the file manager tried to move.

dstPath

The path of the intended destination for the item in srcPath.

Return Value

YES if the operation should proceed or NO if it should be aborted. If you do not implement this method, the file manager assumes a response of NO.

Discussion

The file manager calls this method when there is a problem moving the item to the specified location. If you return YES, the file manager proceeds to remove the item from its current location as if the move operation had completed successfully.

This method performs the same task as the fileManager:shouldProceedAfterError:movingItemAtURL:toURL: method, which is preferred over this method in OS X v10.6 and later.

Availability
  • Available in OS X v10.5 and later.
  • Available as part of an informal protocol prior to OS X v10.7.
Declared In
NSFileManager.h

fileManager:shouldProceedAfterError:movingItemAtURL:toURL:

Asks the delegate if the move operation should continue after an error occurs while moving the item at the specified URL.

- (BOOL)fileManager:(NSFileManager *)fileManager shouldProceedAfterError:(NSError *)error movingItemAtURL:(NSURL *)srcURL toURL:(NSURL *)dstURL
Parameters
fileManager

The file manager object that attempted to move the item.

error

The error that occurred while trying to move the item in srcURL.

srcURL

The URL of the file or directory that the file manager tried to move.

dstURL

The URL of the intended destination for the item in srcURL.

Return Value

YES if the operation should proceed or NO if it should be aborted. If you do not implement this method, the file manager assumes a response of NO.

Discussion

The file manager calls this method when there is a problem moving the item to the specified location. If you return YES, the file manager proceeds to remove the item from its current location as if the move operation had completed successfully.

This method performs the same task as the fileManager:shouldProceedAfterError:movingItemAtPath:toPath: method and is preferred over that method in OS X v10.6 and later.

Availability
  • Available in OS X v10.6 and later.
  • Available as part of an informal protocol prior to OS X v10.7.
Declared In
NSFileManager.h

fileManager:shouldProceedAfterError:removingItemAtPath:

Asks the delegate if the operation should continue after an error occurs while removing the item at the specified path.

- (BOOL)fileManager:(NSFileManager *)fileManager shouldProceedAfterError:(NSError *)error removingItemAtPath:(NSString *)path
Parameters
fileManager

The file manager object that attempted to remove the item.

error

The error that occurred during the attempt to copy.

path

The path for the file or directory that the file manager tried to delete.

Return Value

YES if the operation should proceed or NO if it should be aborted. If you do not implement this method, the file manager assumes a response of NO.

Discussion

The file manager calls this method when there is a problem deleting the item to the specified location. If you return YES, the file manager continues deleting any remaining items and ignores the error.

This method performs the same task as the fileManager:shouldProceedAfterError:removingItemAtURL: method, which is preferred over this method in OS X v10.6 and later.

Availability
  • Available in OS X v10.5 and later.
  • Available as part of an informal protocol prior to OS X v10.7.
Declared In
NSFileManager.h

fileManager:shouldProceedAfterError:removingItemAtURL:

Asks the delegate if the operation should continue after an error occurs while removing the item at the specified URL.

- (BOOL)fileManager:(NSFileManager *)fileManager shouldProceedAfterError:(NSError *)error removingItemAtURL:(NSURL *)URL
Parameters
fileManager

The file manager object that attempted to remove the item.

error

The error that occurred while attempting to remove the item at URL.

URL

The URL for the file or directory that the file manager tried to delete.

Return Value

YES if the operation should proceed or NO if it should be aborted. If you do not implement this method, the file manager assumes a response of NO.

Discussion

The file manager calls this method when there is a problem deleting the item to the specified location. If you return YES, the file manager continues deleting any remaining items and ignores the error.

This method performs the same task as the fileManager:shouldProceedAfterError:removingItemAtPath: method and is preferred over that method in OS X v10.6 and later.

Availability
  • Available in OS X v10.6 and later.
  • Available as part of an informal protocol prior to OS X v10.7.
Declared In
NSFileManager.h

fileManager:shouldRemoveItemAtPath:

Asks the delegate whether the item at the specified path should be deleted.

- (BOOL)fileManager:(NSFileManager *)fileManager shouldRemoveItemAtPath:(NSString *)path
Parameters
fileManager

The file manager object that is attempting to remove the file or directory.

path

The path to the file or directory that the file manager is attempting to delete.

Return Value

YES if the specified item should be deleted or NO if it should not be deleted.

Discussion

Removed items are deleted immediately and not placed in the Trash. If the specified item is a directory, returning NO prevents both the directory and its children from being deleted.

This method performs the same task as the fileManager:shouldRemoveItemAtURL: method, which is preferred over this method in OS X v10.6 and later.

Availability
  • Available in OS X v10.5 and later.
  • Available as part of an informal protocol prior to OS X v10.7.
Declared In
NSFileManager.h

fileManager:shouldRemoveItemAtURL:

Asks the delegate whether the item at the specified URL should be deleted.

- (BOOL)fileManager:(NSFileManager *)fileManager shouldRemoveItemAtURL:(NSURL *)URL
Parameters
fileManager

The file manager object that is attempting to remove the file or directory.

URL

The URL indicating the file or directory that the file manager is attempting to delete.

Return Value

YES if the specified item should be removed or NO if it should not be removed.

Discussion

Removed items are deleted immediately and not placed in the Trash. If the specified item is a directory, returning NO prevents both the directory and its children from being deleted.

This method performs the same task as the fileManager:shouldRemoveItemAtPath: method and is preferred over that method in OS X v10.6 and later.

Availability
  • Available in OS X v10.6 and later.
  • Available as part of an informal protocol prior to OS X v10.7.
Declared In
NSFileManager.h