It looks like on Cocoa there are many ways to move file/folder-directory to Trash:
- [[[NSWorkspace sharedWorkspace] performFileOperation:NSWorkspaceRecycleOperation]
- [[NSWorkspace sharedWorkspace] recycleURLs:]
- [NSFileManager trashItemAtURL:]
- [NSFileManager removeItemAtPath:]
- [NSFileManager removeItemAtURL:]
It would be nice to understand what the difference is by either reading an explanation here or a link to the official Apple docs.
Also if someone knows a universal way of moving a file/non-empty directory to Trash, it would be nice to know.
This is deprecated, as of OS X 10.11, so no point in using it.
This is probably the one you want. It's asynchronous, so your application can continue to operate while the files are being moved to the trash.
This is similar to option 2, but it's synchronous, and only handles one file at a time.
This doesn't trash the file, it deletes it permanently, and immediately.
This is just like option 4, except using a file:// URL instead of a path. More-convenient when you already have a URL rathe than a path.
The reference pages for NSWorkspace and NSFileManager cover all of the differences between these methods fairly well.
Here's a quick sample, which uses recycleUrls: to delete a file or folder named "Junk" on the user's desktop: