Search code examples
iosobjective-cios7ios8nsfilemanager

How to filter array and let stay only strings end with .png


I am reading files from folder, folder contains .pngs but I get additionally Thumb.db file in every folder and all others are .pngs. I read content as

NSArray *directoryContent = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:path error:NULL];

How to remove all files which contains .db in array or to stay just which ends with .png ?


Solution

  • I think by using NSPredicate method you can get exact values

    NSArray *directoryContent = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:path error:NULL];
    NSString *str              = @".png"
    NSPredicate *sPredicate    = [NSPredicate predicateWithFormat:@"SELF contains[c] %@",str];
    NSArray *predicateArray    = [directoryContent filteredArrayUsingPredicate:sPredicate];