From a cocoa app I need to move files to trash and this is enough simple using NSWorkspaceRecycleOperation but the file on trash can't be restore to its original position.
The restore seems to work only from Finder.
I need a solution using standard API and running on Snow Leopard 10.6.x or above
In 10.8+ NSFileManager
trashItemAtURL:resultingItemURL:error:
moves file to trash with the "Put Back" option (it also moves the file synchronously and doesn't emit sounds).
There's no good method for older systems, but you can use new method where it's available and have fallback for older systems:
[[NSFileManager defaultManager]
respondsToSelector:@selector(trashItemAtURL:resultingItemURL:error:)]
I just now discovered that if I pass a valid NSURL ** instead of nil as the resultingItemURL: parameter to NSFileManager trashItemAtURL:resultingItemURL:error:, then I can put back the files from trash. Even though I do nothing with the resultingItemURL afterwards.
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