Skip to content

Instantly share code, notes, and snippets.

@makevoid
Created January 11, 2010 02:56
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 makevoid/273957 to your computer and use it in GitHub Desktop.
Save makevoid/273957 to your computer and use it in GitHub Desktop.
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