• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Putting files in Trash [revisited]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >Putting files in Trash (From: Steve Gehrman <email@hidden>)

  • Prev by Date: Re: NSDrawer and DrawContent
  • Next by Date: Re : Simple Question
  • Previous by thread: Putting files in Trash
  • Next by thread: Re: Putting files in Trash
  • Index(es):
    • Date
    • Thread