I need to have 2 methods : one for knowing if a file is hidden and the other one to set a file as hidden. I didn't get the aswer in developper documentation...
Anybody?
Thanks a lot ! Jérôme
I need to have 2 methods : one for knowing if a file is hidden and the other one to set a file as hidden. I didn't get the aswer in developper documentation...
Anybody?
Thanks a lot ! Jérôme
Files that begin with a "." will be hidden in Finder by default, so you could test if the file start with a dot, for example :
NSString* filename = //Something
if([string hasPrefix:@"."]) {
//The file is hidden
}
To make the file invisible you could rename the file prepending a period to the name.
You can use NSFileManager
to list files in a directory.
NSURL *directoryURL = [NSURL fileURLWithPath:(NSString*)path];
NSArray *filteredContents = [[NSFileManager defaultManager] contentsOfDirectoryAtURL:directoryURL
includingPropertiesForKeys:[NSArray arrayWithObject:NSURLNameKey]
options:NSDirectoryEnumerationSkipsHiddenFiles
error:nil];
With the NSDirectoryEnumerationSkipsHiddenFiles
option specified, it will skip all hidden files in the directory. You can then perform a similar method, one that returns all files in a directory.
NSArray *allContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:(NSString *path) error:nil];
Whatever files are in allContents
that aren't in filteredContents
will presumably be hidden files.