Re: NSFileManager fun & games
Re: NSFileManager fun & games
- Subject: Re: NSFileManager fun & games
- From: Jeremy Dronfield <email@hidden>
- Date: Wed, 1 Dec 2004 10:54:49 +0000
On 1 Dec 2004, at 8:04 am, Charles Srstka wrote:
On Dec 1, 2004, at 12:29 AM, Duncan Campbell wrote:
I would like to only produce the list of files/folder you get when
you click on the "Macintosh HD" icon on the desktop - i.e. beginning
with "Applications", not showing any of the "." files/folders
(hidden) etc.... - is there a method to produce this list?
Obviously I could just look for a "." as the 1st char of the
filename, but it seems there would be a method that gives me what i
am after, based on permissions etc?
I haven't tried it myself, but - [NSFileManager
componentsToDisplayForPath:] looks like it might be what you need.
-[NSFileManager componentsToDisplayForPath:] produces an array of
user-displayable path components for the path provided, not visible
directory contents at the path. For example, doing
NSLog(@"%@", [[NSFileManager defaultManager]
componentsToDisplayForPath:NSHomeDirectory()]);
produces an array like so:
0 : <CFString 0x3a0f70 [0xa01900e0]>{contents = "Macintosh HD"}
1 : <CFString 0x3a2130 [0xa01900e0]>{contents = "Users"}
2 : <CFString 0x3a2120 [0xa01900e0]>{contents = "myuseraccount"}
To the original poster: You can use the following method to check for
file visibility. (It's designed for checking one path, so is not
efficient for enumerating directories; you'll probably want to init and
keep dotHiddens in an accessor somewhere rather than creating it for
each call as here):
- (BOOL)isVisibleFileAtPath:(NSString *)path {
BOOL visible = YES;
if ([[path lastPathComponent] hasPrefix:@"."]) {
visible = NO;
} else {
// check if file is in .hidden
NSString *hiddenFile = [NSString
stringWithContentsOfFile:@"/.hidden"];
NSArray *dotHiddens = [hiddenFile componentsSeparatedByString:@"\n"];
visible = ![dotHiddens containsObject:[path lastPathComponent]];
// use Carbon to check if file has kIsInvisible finder flag
FSRef possibleInvisibleFile;
FSCatalogInfo catalogInfo;
OSStatus errStat = FSPathMakeRef([path fileSystemRepresentation],
&possibleInvisibleFile, nil);
FSGetCatalogInfo(&possibleInvisibleFile, kFSCatInfoFinderInfo,
&catalogInfo, nil, nil, nil);
if (((FileInfo*)catalogInfo.finderInfo)->finderFlags & kIsInvisible)
visible = NO;
}
return visible;
}
Regards,
Jeremy
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden