Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recommended way to copy arbitrary files using Cocoa

I need to copy file from one OS X volume to another OS X volume. While an *.app isn't strictly speaking a file but a folder, user expect them to be a unit. Thus, if user selects a file, the app should not show its folder's contents, but copy it as a unit.

Therefore I ask, if there exists a recommended way to copy files using pure Cocoa code.

Optional: Which command line tool provides help and could be utilized by a Cocoa application.

like image 274
SteAp Avatar asked Dec 04 '22 05:12

SteAp


1 Answers

NSFileManager is your friend:

NSError *error = nil;
if ([[NSFileManager defaultManager] copyItemAtPath:@"path/to/source" toPath:@"path/to/destination" error:&error])
{
    // copy succeeded
}
else
{
    // copy failed, print error
}
like image 69
Richard J. Ross III Avatar answered Dec 15 '22 02:12

Richard J. Ross III