As far as I know, hidden files on OS X are determined by either the filename being prefixed with a period or by a special "invisible" bit that is tracked by the Finder.
A few years back, I had to write something that toggled the visibility of a given file, and I found it was actually a lot more complicated than I expected. The crux of it was obtaining a Finder info (FInfo
) record for the file and checking if the kIsInvisible
bit was set. Here's the method I wrote for toggling file visibility—I think a lot of it is relevant to your task at hand, although you'll 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's 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's 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's 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 Apple's documentation on the Finder Interface, if you want more information. Hope this helps.