Skip to content

Instantly share code, notes, and snippets.

@brennon
Created April 15, 2012 23:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brennon/2395305 to your computer and use it in GitHub Desktop.
Save brennon/2395305 to your computer and use it in GitHub Desktop.
Problem examples
- (BOOL)directoryIsEmpty:(NSString *)path {
NSFileManager *fileManager = [NSFileManager defaultManager];
if ([[fileManager directoryContentsAtPath:path] count] > 0)
return NO;
else
return YES;
}
- (BOOL)directoryIsEmpty:(NSString *)path {
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error = nil;
if ([[fileManager contentsOfDirectoryAtPath:path error:&error] count] > 0)
return NO;
else
return YES;
}
- (void)printDirectoryContents:(NSString *)path {
NSFileManager *fileManager = [NSFileManager defaultManager];
NSArray *contents = [fileManager directoryContentsAtPath:path];
for (NSString *directoryItem in contents) {
NSLog(@"%@", directoryItem);
}
}
- (void)printDirectoryContents:(NSString *)path {
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error = nil;
NSArray *contents = [fileManager contentsOfDirectoryAtPath:path error:&error];
if (!error)
for (NSString *directoryItem in contents) {
NSLog(@"%@", directoryItem);
}
else
// Do something with error
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment