• 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: How determine if file is in Trash, given Path or Alias
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How determine if file is in Trash, given Path or Alias


  • Subject: Re: How determine if file is in Trash, given Path or Alias
  • From: Martin Wierschin <email@hidden>
  • Date: Thu, 28 May 2009 15:49:45 -0700

BOOL isInTrash(NSString* path) {
    FSRef fsRef;
    Boolean result = false ;
    OSStatus err = FSPathMakeRef(
                                 (UInt8*)[path UTF8String],
                                 &fsRef,
                                 NULL) ;
    if (err == noErr) {
        FolderType folderType ;
        FSDetermineIfRefIsEnclosedByFolder (
                                            kOnAppropriateDisk,
                                            kTrashFolderType,
                                            &fsRef,
                                            &result
                                            ) ;
    }

    return (result == true) ;
}

This is a nice trick, I wasn't aware of that function, thanks. Perhaps a minor improvement (one call instead of two):


- (BOOL) isTrashedFileAtPath:(NSString*)path
{
Boolean inTrash = false;
const UInt8* utfPath = (UInt8*)[path UTF8String];
OSStatus err = DetermineIfPathIsEnclosedByFolder(kOnAppropriateDisk, kTrashFolderType, utfPath, false, &inTrash);
return (noErr == err) ? (true == inTrash) : NO;
}


Probably it does the same thing behind the scenes, but why not.

~Martin

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >How determine if file is in Trash, given Path or Alias (From: Jerry Krinock <email@hidden>)
 >Re: How determine if file is in Trash, given Path or Alias (From: "Adam R. Maxwell" <email@hidden>)
 >Re: How determine if file is in Trash, given Path or Alias (From: Jerry Krinock <email@hidden>)

  • Prev by Date: Hiding process list app icon for GUI apps
  • Next by Date: CABasicAnimation leaking?
  • Previous by thread: Re: How determine if file is in Trash, given Path or Alias
  • Next by thread: Creating, Constructing and Managing Dynamic (Sub)Views
  • Index(es):
    • Date
    • Thread