Alex Rivera | Logout

How to check if a folder exists in Cocoa & Objective-C?

Asked 2008-09-19T03:47:45.580
47

How to check if a folder (directory) exists in Cocoa using Objective-C?

Edit
Report

1 Answer

2

If your have a NSURL object as path, it's better to use path to convert it into NSString.

NSFileManager*fm = [NSFileManager defaultManager];

NSURL* path = [[[fm URLsForDirectory:NSDocumentDirectory 
                           inDomains:NSUserDomainMask] objectAtIndex:0]                           
                                 URLByAppendingPathComponent:@"photos"];

NSError *theError = nil;
if(![fm fileExistsAtPath:[path path]]){
    NSLog(@"dir doesn't exists");
}else
    NSLog(@"dir exists");
answered 2013-04-11T19:09:01.833

Your Answer