views:

241

answers:

1

I have an NSString containing a path, but it could be either a file, or a directory.

Is there an equivalent to the Python os.path.isdir() and os.path.isfile() methods in Cocoa?

+8  A: 

See the NSFileManager Class Reference

[[NSFileManager defaultManager] fileExistsAtPath:pathname 
                                isDirectory:&directoryFlag];

For example:

NSString *file = @"/tmp/";
BOOL isDir;
if([[NSFileManager defaultManager]
     fileExistsAtPath:file isDirectory:&isDir] && isDir){
    NSLog(@"Is directory");
}
htw