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" ?
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" ?
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...)