首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

NSFileManager有关

2012-12-27 
NSFileManager相关枚举相同格式的文件:You can achieve this pretty easily with the help of NSPredicate

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;}

热点排行