iphone - NSPredicate endswith multiple files -
i trying filter array using predicate checking files ending in set of extensions. how it?
would close 'self endswith in %@' work? thanks!
nsarray * dircontents = [[nsfilemanager defaultmanager] contentsofdirectoryatpath:documentsdirectorypath error:nil]; nsarray * files = [dircontents filteredarrayusingpredicate: [nspredicate predicatewithformat:@"self contains %@", [nsarray arraywithobjects:@".mp4", @".mov", @".m4v", @".pdf", @".doc", @".xls", nil] ]];
you don't want contains array, want in. ideally want filter path extension. so
nsarray *extensions = [nsarray arraywithobjects:@"mp4", @"mov", @"m4v", @"pdf", @"doc", @"xls", nil]; nsarray *dircontents = [[nsfilemanager defaultmanager] contentsofdirectoryatpath:documentsdirectorypath error:nil]; nsarray *files = [dircontents filteredarrayusingpredicate:[nspredicate predicatewithformat:@"pathextension in %@", extensions]];
Comments
Post a Comment