Instance Method


Copies the directory or file specified in a given path to a different location in the file system identified by another path.


- (BOOL)copyPath:(NSString *)src toPath:(NSString *)dest handler:(id)handler;



The location of the source file.


The location to which to copy the file specified by source.


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 method automatically returns NO.

Return Value

YES if the copy operation is successful. If the operation is not successful, but the callback handler of fileManager:shouldProceedAfterError: returns YES, copyPath:toPath:handler: also returns YES. Otherwise this method returns NO. The method also attempts to make the attributes of the directory or file at destination identical to source, but ignores any failure at this attempt.


If source is a file, the method creates a file at destination that holds the exact contents of the original file (this includes BSD special files). If source is a directory, the method creates a new directory at destination and recursively populates it with duplicates of the files and directories contained in source, preserving all links. The file specified in source must exist, while destination must not exist prior to the operation. When a file is being copied, the destination path must end in a filename—there is no implicit adoption of the source filename. Symbolic links are not traversed but are themselves copied. File or directory attributes—that is, metadata such as owner and group numbers, file permissions, and modification date—are also copied.

The handler callback mechanism 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.

Special Considerations

Because this method does not return error information, it has been deprecated as of OS X v10.5. Use copyItemAtURL:toURL:error: instead.

See Also

Deprecated Methods

- movePath:toPath:handler:

Moves the directory or file specified by a given path to a different location in the file system identified by another path.

- removeFileAtPath:handler:

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

- changeFileAttributes:atPath:

Changes the attributes of a given file or directory.

- fileAttributesAtPath:traverseLink:

Returns a dictionary that describes the POSIX attributes of the file specified at a given.

- fileSystemAttributesAtPath:

Returns a dictionary that describes the attributes of the mounted file system on which a given path resides.

- directoryContentsAtPath:

Returns the directories and files (including symbolic links) contained in a given directory.

- createDirectoryAtPath:attributes:

Creates a directory (without contents) at a given path with given attributes.

- createSymbolicLinkAtPath:pathContent:

Creates a symbolic link identified by a given path that refers to a given location.

- pathContentOfSymbolicLinkAtPath:

Returns the path of the directory or file that a symbolic link at a given path refers to.

- linkPath:toPath:handler:

Creates a link from a source to a destination.

- 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.

- 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.