Created
March 9, 2014 15:05
-
-
Save oppai/9449152 to your computer and use it in GitHub Desktop.
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
#import <Foundation/Foundation.h> | |
@interface Finder : NSObject | |
+ (NSString*)findFile:(NSString*)name In:(NSString*)dirname; | |
@end | |
@implementation Finder | |
+ (NSString*)findFile:(NSString*)name In:(NSString*)dirname | |
{ | |
NSFileManager *file_manager = [NSFileManager defaultManager]; | |
NSString *target_path; | |
NSError *error; | |
NSArray *list = [file_manager contentsOfDirectoryAtPath:dirname | |
error:&error]; | |
if ( !error ){ | |
for (NSString *path in list) { | |
BOOL is_dir; | |
[file_manager fileExistsAtPath:path isDirectory:&is_dir]; | |
if (is_dir) { | |
target_path = [self findFile:name In:path]; | |
}else if ([path rangeOfString:name].location == NSNotFound) { | |
target_path = path; | |
} | |
if (target_path) break; | |
} | |
} else { | |
NSLog(@"%@",error.description); | |
} | |
return target_path; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment