Snippet #31
Language: Objective-C, Author: Zachary Schneirov
License: Public domain
Objective-C class method to set the invisibility flag of a file.
+ (BOOL)setInvisibilityFlag:(BOOL)invisible forPath:(NSString*)path { FSRef sourceRef; OSErr err = FSPathMakeRef((UInt8*)[path fileSystemRepresentation], &sourceRef, NULL); if (err == noErr) { FSCatalogInfo catalogInfo; /* get the current finderInfo */ if ((err = FSGetCatalogInfo(&sourceRef, kFSCatInfoFinderInfo, &catalogInfo, NULL, NULL, NULL)) != noErr) { NSLog(@"FSGetCatalogInfo error: %d", err); return NO; } if (invisible) { /* OR in the bits */ ((FileInfo *)&catalogInfo.finderInfo)->finderFlags |= kIsInvisible; } else { /* AND out the bits */ ((FileInfo *)&catalogInfo.finderInfo)->finderFlags &= ~kIsInvisible; } /* save the modified finderInfo */ if ((err = FSSetCatalogInfo(&sourceRef, kFSCatInfoFinderInfo, &catalogInfo)) != noErr) { NSLog(@"FSSetCatalogInfo error: %d", err); return NO; } return YES; } else { NSLog(@"error getting fsref from path %@: %d", path, err); } return NO; }
Compatible with:
- Mac OS X 10.0
- Mac OS X 10.1
- Mac OS X 10.2
- Mac OS X 10.3
- Mac OS X 10.4 PPC
- Mac OS X 10.4 Intel
- Mac OS X 10.5 PPC
- Mac OS X 10.5 Intel
Comments
Comment feed
