Instance Method

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.

Declaration

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

Parameters

source

The path of a file or directory to move. source must exist.

destination

The path to which source is moved. destination must not yet exist. The destination path must end in a filename; there is no implicit adoption of the source filename.

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

Return Value

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

Discussion

If source is a file, the method creates a file at destination that holds the exact contents of the original file and then deletes the original file. If source is a directory, movePath:toPath:handler: creates a new directory at destination and recursively populates it with duplicates of the files and directories contained in source. It then deletes the old directory and its contents. Symbolic links are not traversed, however links are preserved. File or directory attributes—that is, metadata such as owner and group numbers, file permissions, and modification date—are also moved.

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.

If a failure in a move operation occurs, either the preexisting path or the new path remains intact, but not both.

Special Considerations

Because this method does not return error information, it has been deprecated as of OS X v10.5. Use moveItemAtURL:toURL: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.