Re: Finding a file or application
Re: Finding a file or application
- Subject: Re: Finding a file or application
- From: Nick Zitzmann <email@hidden>
- Date: Fri, 19 Sep 2003 00:06:12 -0700
On Thursday, September 18, 2003, at 11:33 PM, Chad Armstrong wrote:
In Cocoa, how might I check if a file exists in a specified spot or
not? Say a user types in a file name into a text field, I would like
to check that the input is valid before doing anything. The same
could apply to finding a particular application on the system.
I hate to say this, but... RTFM. From the NSFileManager class
documentation:
<begin>
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:
<end>
Nick Zitzmann
AIM/iChat: dragonsdontsleep
Check out my software page:
http://seiryu.home.comcast.net/
"I have always wished that my computer would be as easy to use as my
telephone. My wish has come true. I no longer know how to use my
telephone." - Bjarne Stroustrup
_______________________________________________
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.