Re: Putting files in Trash [revisited]
Re: Putting files in Trash [revisited]
- Subject: Re: Putting files in Trash [revisited]
- From: "Tomas Zahradnicky, Jr." <email@hidden>
- Date: Mon, 12 Nov 2001 16:32:40 +0100
I'm putting files in the trash with:
[[NSWorkspace sharedWorkspace]
performFileOperation:NSWorkspaceRecycleOperation
source:sourceDirPath destination:@"" files:array tag:&resultTag];
This work, but I can't get the Finder to update the window. If I
log out and log back in, the items show.
Steve,
I've needed the same and I wrote this code. It works quite good for
me and it requires CoreServices framework. I tested it with both
adding and removing items from trash.
#import <Foundation/Foundation.h>
#import <CoreServices/CoreServices.h>
OSStatus invalTrashContents()
{
// trash is located in ~/.Trash and this folder does not
// exist if it is empty. If you call invalTrashContents
// on trash with 0 files trash folder is attempted to be
// deleted. If it exists, trash folder is invalidated
// and finder views are updated.
OSStatus err = 0;
FSRef trashRef;
NSDirectoryEnumerator *enumerator;
Boolean isDirectory;
NSString *trashpath = @"~/.Trash";
NSString *completepath;
completepath = [trashpath stringByExpandingTildeInPath];
err = FSPathMakeRef((const unsigned char*)[completepath cString],
&trashRef, &isDirectory);
if(err!=noErr || !isDirectory)
{
// trash does not exist. don't do anything
return err;
}
err =
FNNotify(&trashRef,kFNDirectoryModifiedMessage,kNilOptions);
return err;
}
-Tomas
--
# Tomas Zahradnicky, Jr
# The Czech Technical University
# FEL-CTU, Prague