As far as I know, hidden files in OS X are defined either by a file name preceded by a period, or by a special βinvisibleβ bit that is tracked by Finder.
A few years ago, I had to write something that changed the visibility of this file, and I found that it was actually much more complicated than I expected. Its essence was to get the file Finder ( FInfo ) for the file and check for the presence of the kIsInvisible bit. Here's the method I wrote to switch file visibility - I think a lot of this is relevant to your task, although you obviously have to tweak it a bit.
- (BOOL)toggleVisibilityForFile:(NSString *)filename isDirectory:(BOOL)isDirectory { // Convert the pathname to HFS+ FSRef fsRef; CFURLRef url = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, (CFStringRef)filename, kCFURLPOSIXPathStyle, isDirectory); if (!url) { NSLog(@"Error creating CFURL for %@.", filename); return NO; } if (!CFURLGetFSRef(url, &fsRef)) { NSLog(@"Error creating FSRef for %@.", filename); CFRelease(url); return NO; } CFRelease(url); // Get the file catalog info FSCatalogInfo *catalogInfo = (FSCatalogInfo *)malloc(sizeof(FSCatalogInfo)); OSErr err = FSGetCatalogInfo(&fsRef, kFSCatInfoFinderInfo, catalogInfo, NULL, NULL, NULL); if (err != noErr) { NSLog(@"Error getting catalog info for %@. The error returned was: %d", filename, err); free(catalogInfo); return NO; } // Extract the Finder info from the FSRef catalog info FInfo *info = (FInfo *)(&catalogInfo->finderInfo[0]); // Toggle the invisibility flag if (info->fdFlags & kIsInvisible) info->fdFlags &= ~kIsInvisible; else info->fdFlags |= kIsInvisible; // Update the file visibility err = FSSetCatalogInfo(&fsRef, kFSCatInfoFinderInfo, catalogInfo); if (err != noErr) { NSLog(@"Error setting visibility bit for %@. The error returned was: %d", filename, err); free(catalogInfo); return NO; } free(catalogInfo); return YES; }
Here's the Apple documentation for the Finder Interface if you would like more information. Hope this helps.
source share