Re: Move a file to the Trash
Re: Move a file to the Trash
- Subject: Re: Move a file to the Trash
- From: Rosyna <email@hidden>
- Date: Sat, 9 Nov 2002 21:13:10 -0700
Does this code work on at least 10.1.5? Does it handle cases where an
item in the trash is the same name as a file being moved into it?
(the finder does)
In any case, it might be best to use AppleEvents and use
kAECoreSuite/kAEDelete to move the file to the trash. Excellent
AppleEvent sample code can be found at
http://developer.apple.com/samplecode/Sample_Code/Interapplication_Comm/MoreAppleEvents.htm
Ack, at 11/6/02, Clark Mueller said:
What about NSWorkspace? I'm surprised nobody at least suggested this...
Following is a chunk from a class that I use in my app Modifier to do
things with files (http://www.finikin.com). Most everyone who's ever
asked a question about file attributes on this list has gotten a code
snippet from said class from me. This is what I use, and it hasn't
turned up as a problem, so far as I know... Here's the code:
- (BOOL)trashWithPath:(NSString *)path{
// Moves 'path' to the trash, a la NSWorkspace.
NSWorkspace *ws = [NSWorkspace sharedWorkspace];
if(![ws performFileOperation:NSWorkspaceRecycleOperation
source:[path stringByDeletingLastPathComponent] destination:@""
files:[NSArray arrayWithObject:[path lastPathComponent]] tag:0]){
return NO;
}
else{
[self wakeUpPath:path];
return YES;
}
}
--
Sincerely,
Rosyna Keller
Technical Support/Holy Knight/Always needs a hug
Unsanity: Unsane Tools for Insanely Great People
---
Please include any previous correspondence in replies, it helps me
remember what we were talking about. Thanks.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.