1
0
mirror of https://github.com/arsenetar/dupeguru.git synced 2024-11-17 20:49:02 +00:00
dupeguru/base/qt/osx/SendToTrashProject/SendToTrash.m
hsoft 047b4aff0c [#52] Added file recycling support on OS X.
--HG--
extra : convert_revision : svn%3Ac306627e-7827-47d3-bdf0-9a457c9553a1/trunk%40102
2009-08-31 12:04:43 +00:00

24 lines
1018 B
Objective-C

#import <Cocoa/Cocoa.h>
int main (int argc, const char * argv[]) {
if(argc == 1){
NSLog(@"A file path to send to trash is needed");
return 1;
}
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSString *filepath = [NSString stringWithCString:argv[1] encoding:NSUTF8StringEncoding];
NSLog(@"%@",filepath);
NSMutableArray *split = [NSMutableArray arrayWithArray:[filepath componentsSeparatedByString:@"/"]];
NSString *filename = [split lastObject];
[split removeLastObject];
NSString *dirpath = [split componentsJoinedByString:@"/"];
int result;
[[NSWorkspace sharedWorkspace] performFileOperation:NSWorkspaceRecycleOperation
source:dirpath
destination:@""
files:[NSArray arrayWithObject:filename]
tag:&result];
[pool drain];
return result;
}