读书人

NSFileManager有关

发布时间: 2012-12-27 10:17:10 作者: rapoo

NSFileManager相关
枚举相同格式的文件:
You can achieve this pretty easily with the help of NSPredicate, like so:

NSString *bundleRoot = [[NSBundle mainBundle] bundlePath];NSFileManager *fm = [NSFileManager defaultManager];NSArray *dirContents = [fm contentsOfDirectoryAtPath:bundleRoot error:nil];NSPredicate *fltr = [NSPredicate predicateWithFormat:@"self ENDSWITH '.jpg'"];NSArray *onlyJPGs = [dirContents filteredArrayUsingPredicate:fltr];


Checking for file existence:

+(BOOL)fileExistsAtAbsolutePath:(NSString*)filename {    BOOL isDirectory;    BOOL fileExistsAtPath = [[NSFileManager defaultManager] fileExistsAtPath:filename isDirectory:&isDirectory];    return fileExistsAtPath && !isDirectory;}


Checking for directory existence:

+(BOOL)directoryExistsAtAbsolutePath:(NSString*)filename {    BOOL isDirectory;    BOOL fileExistsAtPath = [[NSFileManager defaultManager] fileExistsAtPath:filename isDirectory:&isDirectory];    return fileExistsAtPath && isDirectory;}

读书人网 >移动开发

热点推荐