I was wondering, is there a best practice to write an OSX programm that copies or moves a file from one place to another?
Bonus question: How do I get percentages a la "copy 12% complete" with one of these methods?
Thanks for your help!
Select the file you want to copy by clicking on it once. Right-click and pick Copy, or press Ctrl + C . Navigate to another folder, where you want to put the copy of the file. Click the menu button and pick Paste to finish copying the file, or press Ctrl + V .
To move a file, hold down the Shift key while dragging. You can also use the middle mouse button to drag files. In this case, gThumb will ask you if you wish to copy the files, move the files, or cancel the operation. Select the files to be transferred, right-click on the selection, and choose Copy to... or Move to....
Generally, Moving files will be faster because when moving, it will just change the links, not the Actual Position on the physical device. While copying will actually read and write the information to other place and hence takes more time.
NSFileManager and NSWorkspace both have methods to move, copy, and delete files. Usually you'd use NSFileManager since its easier to work with:
if ( [[NSFileManager defaultManager] isReadableFileAtPath:source] ) [[NSFileManager defaultManager] copyItemAtURL:source toURL:destination error:nil];
However, NSWorkspace can easily move files to the Trash, which NSFileManager can't do.
[[NSWorkspace sharedWorkspace] performFileOperation:NSWorkspaceRecycleOperation source:foldername destination:@"" files:filenamesArray tag:&tag];
Check the documentation for a more complete description of the two classes. (NSFileManager, NSWorkspace)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With