Created
October 5, 2012 14:24
-
-
Save mikeabdullah/3840055 to your computer and use it in GitHub Desktop.
Searching for subfolders
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (NSNumber *)directoryContainsASubfolder:(NSURL *)directoryURL error:(NSError **)error; | |
{ | |
NSArray *contents = [[NSFileManager defaultManager] | |
contentsOfDirectoryAtURL:directoryURL | |
includingPropertiesForKeys:nil | |
options:NSDirectoryEnumerationSkipsHiddenFiles | |
error:error]; | |
if (!contents) return nil; | |
for (NSURL *aURL in contents) | |
{ | |
// Ignore failures for resource values. Such a failure makes it incredibly unlikely | |
// the URL is a folder we can actually *list* | |
NSNumber *isDirectory; | |
if ([aURL getResourceValue:&isDirectory forKey:NSURLIsDirectory error:error] && | |
[isDirectory boolValue]) | |
{ | |
// If know it's a directory, but don't know if it's a package, treat as a folder | |
NSNumber *isPackage; | |
if (![aURL getResourceValue:&isPackage forKey:NSURLIsPackage error:error] || | |
![isPackage boolValue]) | |
{ | |
// Once we find a non-package directory, that's good enough | |
return @YES; | |
} | |
} | |
} | |
return @NO; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment