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?
See the NSFileManager Class Reference
[[NSFileManager defaultManager] fileExistsAtPath:pathname isDirectory:&directoryFlag]; For example:
NSString *file = @"/tmp/"; BOOL isDir = NO; if([[NSFileManager defaultManager] fileExistsAtPath:file isDirectory:&isDir] && isDir){ NSLog(@"Is directory"); } if the solution from htw doesn't work, try this:
NSString *file = @"/tmp/"; BOOL isDir NSDirectoryEnumerator *dirEnum = [[NSFileManager defaultManager] enumeratorAtPath:file]; while ((file = [dirEnum nextObject])) { [[NSFileManager defaultManager] fileExistsAtPath:file isDirectory:&isDir]; if(isDir){ NSLog(@"%@ is a directory", file); } }