I've an array of strings to be used as a 'filter':
@[@"*.png", @".DS_Store", @"Foobar", @".jpg"]
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]];
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.
You can filter those things you want to list. Remaining will automatically filtered.
Take a look at Predicate Programming Guide