views:

26

answers:

1

I need to move directory with all content to trash. I find in documentation NSWorkspaceRecycleOperation operation, and wrote this code:

NSString *path = [NSString stringWithString:@"/Users/test/Desktop/test"];

NSArray *dirContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:path error:nil];

[[NSWorkspace sharedWorkspace] performFileOperation:NSWorkspaceRecycleOperation 
                                             source:path 
                                        destination:@"" 
                                              files:dirContents 
                                                tag:nil];

It move to trash all contents, but don't move directory itself. So, how can i do this?

+1  A: 

You are currently only performing the recycle operation on the directories contents. Given a directory dir to trash, use something like the following instead:

[[NSWorkspace sharedWorkspace] performFileOperation:NSWorkspaceRecycleOperation 
                               source:[dir stringByDeletingLastPathComponent]
                               destination:@"" 
                               files:[NSArray arrayWithObject:[dir lastPathComponent]]
                               tag:nil];
Georg Fritzsche