How to copy a file from one location to another ?
11/07/03 22:40
What's the command to copy, move, delete, … files in Cocoa ?
The class to manipulate file system objects is NSFileManager.
To copy files use [[NSFileManager defaultManager] copyPath:mySourcePath toPath:myDestpath handler:myHandler].
To move file use [[NSFileManager defaultManager] movePath:mySourcePath toPath:myDestpath handler:myHandler].
To remove a file use [[NSFileManager defaultManager] removeFileAtPath:myPath handler:myHandler].
To create an hard-link use [[NSFileManager defaultManager] linkPath:myPath toPath:myDestpath handler:myHandler].
Of course, the executing process must have appropriate access rights to the file system objects accessed during these operations. (files AND their enclosing directories). Read carrefully the specific documentation to see how each of these routines handle errors, symbolic link traversal, directories creation, etc.
To copy files use [[NSFileManager defaultManager] copyPath:mySourcePath toPath:myDestpath handler:myHandler].
To move file use [[NSFileManager defaultManager] movePath:mySourcePath toPath:myDestpath handler:myHandler].
To remove a file use [[NSFileManager defaultManager] removeFileAtPath:myPath handler:myHandler].
To create an hard-link use [[NSFileManager defaultManager] linkPath:myPath toPath:myDestpath handler:myHandler].
Of course, the executing process must have appropriate access rights to the file system objects accessed during these operations. (files AND their enclosing directories). Read carrefully the specific documentation to see how each of these routines handle errors, symbolic link traversal, directories creation, etc.