views:

13

answers:

1

In xcode, I have many .plist files called : ImageData1.plist, ImageData2.plist ... etc

how can I get the number of .plist files which start with the name "ImageData" ?

+1  A: 

A quick and dirty solution:

int count = 0;

for (int i = 1; i<100; i++) {
    NSString * format = @"ImageData%u";
    NSString * file = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:format,i] ofType:@"plist"];
    BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:file];

    if (fileExists) {
        count ++;
    } else {
        break;
    }
}

NSLog(@"-----> Number of files = %u", count);

This method works if you don't have missing files in the sequence (e.g. ImageData1.plist, ImageData2.plist, ImageData4.plist...)

MaxFish
thanks it worked, plus I didnt use the else condition, cuz i need to count all the files even if there are missing ones in the sequence
SLA