【发布时间】:2013-01-08 06:15:04
【问题描述】:
是否可以在一个文件夹及其所有子文件夹中搜索某种类型的所有文件(例如 mp4)?到目前为止,我可以使用此代码一次为一个文件夹执行此操作:
NSFileManager *fm = [NSFileManager defaultManager];
NSArray *dirContents = [fm contentsOfDirectoryAtPath:cachesPath error:nil];
NSPredicate *fltr = [NSPredicate predicateWithFormat:@"self ENDSWITH '.mp4'"];
NSArray *filesWithAttr = [dirContents filteredArrayUsingPredicate:fltr];
NSLog(@"%@", filesWithAttr);
但我的 cashes 文件夹中有很多子文件夹。我是否必须逐一检查并检查 mp4 文件还是有更简单的解决方案?
提前致谢
【问题讨论】:
-
看看
[fm fileExistsAtPath:yourPath isDirectory:&foo];和[fm subpathsAtPath:yourPath]; -
正是我所需要的。非常感谢
标签: ios search directory subdirectory