Re: NSFileManager and directories
Re: NSFileManager and directories
- Subject: Re: NSFileManager and directories
- From: Neil Earnshaw <email@hidden>
- Date: Thu, 4 Sep 2003 09:26:07 +0100
This looks like the unambiguous way to determine if something is a
directory:
fileExistsAtPath:isDirectory:
- (BOOL)fileExistsAtPath:(NSString *)path isDirectory:(BOOL
*)isDirectory
Returns whether the file specified in path exists. If you want to
determine if path is a directory, specify the address of a boolean
variable for isDirectory; the method indirectly returns YES if path is
a directory. If path begins with a tilde, it must first be expanded
with stringByExpandingTildeInPath, or this method will return NO.The
method traverses final symbolic links.
If you need to further determine if path is a package, use
NSWorkspace's isFilePackageAtPath: .
This example gets an NSArray that identifies the fonts in
/System/Library/Fonts:
NSArray *subpaths;
BOOL isDir;
NSString *fontPath = @"/System/Library/Fonts";
NSFileManager *manager = [NSFileManager defaultManager];
if ([manager fileExistsAtPath:fontPath isDirectory:&isDir] && isDir)
subpaths = [manager subpathsAtPath:fontPath];
See Also: - fileExistsAtPath:
-Neil
On Thursday, September 4, 2003, at 08:25 AM, Francisco Tolmasky wrote:
Is saying something like
NSArray *contents;
if(contents= [[NSFileManager defaultManager] directoryContentsAtPath:
aPath])
//do directory stuff
else
//do file stuff
a safe way to tell if the object at "aPath" is a directory or not?
Francisco Tolmasky
email@hidden
http://users.adelphia.net/~ftolmasky
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.