Re: how to move files to trash?
Re: how to move files to trash?
- Subject: Re: how to move files to trash?
- From: Jérome Foucher <email@hidden>
- Date: Wed, 29 Oct 2003 09:55:25 +0100
On 29 oct. 03, at 09:09, Sascha Kujawa wrote:
>
I am wondering how to move files to trash with Cocoa?
>
>
[fileManager removeFileAtPath:tempPath handler:nil]
>
would permanently delete a file without using the trash.
>
>
So I tried to utilize "movePath", but it does not work this way:
>
[fileManager
>
movePath:tempPath
>
toPath:[@"~/.Trash/" stringByExpandingTildeInPath]
>
handler:nil
>
];
>
>
Any ideas?
I myself use Carbon and Apple Events to do the job :
- (void)moveFileToTrash:(NSString *)filepath {
AppleEvent event, reply;
OSErr err;
OSType adrFinder = 'MACS';
FSRef fileRef;
AliasHandle fileAlias = NULL;
err = FSPathMakeRef([filepath fileSystemRepresentation], &fileRef,
NULL);
if (err != noErr) return;
err = FSNewAliasMinimal(&fileRef, &fileAlias);
if (err != noErr) return;
err = AEBuildAppleEvent('core', 'delo', typeApplSignature,
&adrFinder, sizeof(adrFinder),
kAutoGenerateReturnID, kAnyTransactionID, &event, NULL,
"'----':alis(@@)", fileAlias);
if (err != noErr) return;
err = AESend(&event, &reply, kAEWaitReply, kAENormalPriority,
kAEDefaultTimeout, NULL, NULL);
AEDisposeDesc(&event);
AEDisposeDesc(&reply);
if (fileAlias)
DisposeHandle((Handle)fileAlias);
return;
}
Yes, you can handle the errors smarter. And you might not be interested
in waiting for the AE reply. But this code is a good start.
Hope this helps,
Jerome
_______________________________________________
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.