过滤NSFileManger内容以获取文件' patterns'的列表使用NSPredicate [英] Filter NSFileManger contents for a list of file 'patterns' using NSPredicate
本文介绍了过滤NSFileManger内容以获取文件' patterns'的列表使用NSPredicate的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个字符串数组用作过滤器":
I've an array of strings to be used as a 'filter':
@[@"*.png", @".DS_Store", @"Foobar", @".jpg"]
如何使用上述模式使用NSPredicate过滤掉文件夹的所有内容?
How do I use above pattern to filter out all the contents of a folder using NSPredicate?
这是我到目前为止所得到的:
This is what I've got so far:
NSArray *contents = [fileManager contentsOfDirectoryAtPath:fullPath error:NULL];
NSArray *filter = @[@"*.png", @".DS_Store", @"Foobar", @".jpg"];
NSArray *contents = [contents filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"((pathExtension IN[cd] %@) OR (lastPathComponent IN[cd] %@)) ", filter, filter]];
但是,这并没有给我想要的结果.例如,未过滤 png
文件.另外,我不能使它不区分大小写,因此不会过滤掉 foobar
.
But this doesn't give me the result that I want. For an example png
files are not filtered. Also, I couldn't make this it case-insensitive so foobar
is not filtered out.
推荐答案
查看全文