Reputation: 5323
I am tying to get the content of the trash in a Cocoa application and I was wondering if this is a special path or if I have to use dedicated functions.
Thanks for your help,
Regards,
Upvotes: 0
Views: 1476
Reputation: 7874
You can use URLForDirectory to get Trash directory related to the file, home directory or external Volume.
NSURL *trashURL = [[NSFileManager defaultManager] URLForDirectory:NSTrashDirectory inDomain:NSUserDomainMask appropriateForURL:dirURL create:NO error:&error];
You can call this function for all volumes mounted by using " mountedVolumeURLsIncludingResourceValuesForKeys"
Upvotes: 3
Reputation: 6325
"Macintosh HD>Users>your username>.Trash" It is hidden to finder but you can locate it in the terminal or otherwise. From then on it is a normal folder and you can do whatever functions you would like to it. Could be done like such
NSError *error=nil;
NSString *path=[NSHomeDirectory() stringByAppendingPathComponent:@".Trash"];
NSArray *folderList=[[NSFileManager defaultManager] contentsOfDirectoryAtPath:path error:&error];
Upvotes: 1
Reputation: 86651
There are several special paths for trash items.
.Trash
directory in their home directly..Trashes
directory in its root with a subdirectory for each user. This is so that trash items on removable drives like USB keys stay on the drive.The above are implementation details (that have stayed constant since 10.0) so I'm not sure if it is possible to rely on them. An alternative to going to the directories is to use the scripting bridge to Finder. There's an example in the Scripting Bridge programming guide.
Upvotes: 5