Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Cocoa file search from bundle
// usage:
NSString *filePath = [self pathForItemNamed:@"file.ext" inFolder:[[NSBundle mainBundle] bundlePath]];
+ (NSString *) pathForItemNamed: (NSString *) fname inFolder: (NSString *) path
{
NSString *file;
NSDirectoryEnumerator *dirEnum = [[NSFileManager defaultManager] enumeratorAtPath:path];
while (file = [dirEnum nextObject]) {
//NSLog(@"file: %@", file);
if ([[file lastPathComponent] isEqualToString:fname])
return [path stringByAppendingPathComponent:file];
}
return nil;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment