A file in Finder can be hidden by one of three ways
1. File’s hidden bit is set.
2. File is in hidden file list in folder (.hidden file).
3. File has a “.” at beginning of name.
Beginning in 10.6 use NSURL for referencing files and accessing their metadata. Parsing these values with getResourceValue:forKey:error: using the NSURLIsHiddenKey. However this will not detect the hidden file if it is in the .hidden file. NSURL has a long list of key to get values out of the file’s metadata.
Prior to 10.6
BOOL isInvisibleCFURL(CFURLRef inURL)
LSCopyItemInfoForURL(inURL, kLSRequestAllFlags, &itemInfo);
BOOL isInvisible = itemInfo.flags & kLSItemInfoIsInvisible;
LSItemInfoRecord is a structure which contains the following
flags is structure containing
- kLSItemInfoIsPlainFile Item is a data file (and not, for example, a directory, volume, or UNIX symbolic link).
- kLSItemInfoIsPackage Item is a packaged directory.
- kLSItemInfoIsApplication Item is a single-file or packaged application.
- kLSItemInfoIsContainer Item is a directory (includes packages) or volume.
- kLSItemInfoIsAliasFile Item is an alias file (includes symbolic links).
- kLSItemInfoIsSymlink Item is a UNIX symbolic link.
- kLSItemInfoIsInvisible Item is invisible, because either its name begins with a period or its isInvisible Finder flag is set.
- kLSItemInfoIsNativeApp Item is an application that can run natively in Mac OS X.
- kLSItemInfoIsClassicApp Item is an application that cannot run natively and must be launched in the Classic emulation environment.
- kLSItemInfoAppPrefersNativeItem is an application that can run either natively or in the Classic emulation environment, but prefers to be launched natively. This flag is valid only when kLSItemInfoIsNativeApp is set.
- kLSItemInfoAppPrefersClassic Item is an application that can run either natively or in the Classic emulation environment, but prefers to be launched in the Classic environment. This flag is valid only when kLSItemInfoIsNativeApp is set.
- kLSItemInfoAppIsScriptable Item is an application that can be scripted.
- kLSItemInfoIsVolume Item is the root directory of a volume or mount point.
- kLSItemInfoExtensionIsHidden Item has a hidden filename extension.