Skip to content

Instantly share code, notes, and snippets.

@odrobnik
Created April 4, 2013 11:49
Show Gist options
  • Save odrobnik/5309752 to your computer and use it in GitHub Desktop.
Save odrobnik/5309752 to your computer and use it in GitHub Desktop.
Pictures at URL
- (NSArray *)_picturesInDirectoryAtURL:(NSURL *)URL
{
NSMutableArray *tmpArray = [NSMutableArray array];
NSArray *keys = [NSArray arrayWithObjects:
NSURLIsDirectoryKey, NSURLIsPackageKey, NSURLLocalizedNameKey, nil];
NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager]
enumeratorAtURL:URL
includingPropertiesForKeys:keys
options:(NSDirectoryEnumerationSkipsPackageDescendants | NSDirectoryEnumerationSkipsHiddenFiles)
errorHandler:^(NSURL *url, NSError *error) {
NSLog(@"%@", [error localizedDescription]);
// Handle the error.
// Return YES if the enumeration should continue after the error.
return NO;
}];
// enumerator goes into depth too!
for (NSURL *url in enumerator)
{
NSNumber *isDirectory = nil;
[url getResourceValue:&isDirectory forKey:NSURLIsDirectoryKey error:NULL];
if (![isDirectory boolValue])
{
if ([[url path] isImageFileName])
{
ModelPicture *picture = [[ModelPicture alloc] initWithURL:url];
[tmpArray addObject:picture];
}
}
}
return tmpArray;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment