Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get all file names starting with a prefix from Resource folder

How can we get all file names starting with a prefix from resource folder..

like image 552
xydev Avatar asked Mar 09 '11 10:03

xydev


1 Answers

You can achieve that adapting the following code:

NSArray *files = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:
                  [[NSBundle mainBundle] bundlePath] error:nil];
NSArray *pngs = [files filteredArrayUsingPredicate:
                 [NSPredicate predicateWithFormat:@"self ENDSWITH[cd] '.png'"]];
NSLog(@"%@", pngs);

Running this code you will see the list of PNG's on your bundle. Change the predicate to match with the prefix you want:

NSArray *files = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:
                  [[NSBundle mainBundle] bundlePath] error:nil];
NSArray *filesWithSelectedPrefix = [files filteredArrayUsingPredicate:
                                    [NSPredicate predicateWithFormat:@"self BEGINSWITH[cd] 'prefix'"]];
NSLog(@"%@", filesWithSelectedPrefix);
like image 199
vfn Avatar answered Oct 06 '22 23:10

vfn