Best way to copy or move files with Objective-C?

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)

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)