Reputation: 3532
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
Upvotes: 9
Views: 2756
Reputation: 19
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.
Upvotes: 1
Reputation: 100200
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:)]
Upvotes: 4
Reputation: 1739
Didn't test it, but maybe this method will do it:
recycleURLs:completionHandler:
At least the documentation says "Moves the specified URLs to the trash in the same manner as the Finder."
Best regards, Stephan.
Upvotes: -1