You can achieve this pretty easily with the help of NSPredicate, like so:
NSString *bundleRoot = [[NSBundle mainBundle] bundlePath]; NSFileManager *fm = [NSFileManager defaultManager]; NSArray *dirContents = [fm contentsOfDirectoryAtPath:bundleRoot error:nil]; NSPredicate *fltr = [NSPredicate predicateWithFormat:@"self ENDSWITH '.jpg'"]; NSArray *onlyJPGs = [dirContents filteredArrayUsingPredicate:fltr];
Checking for file existence:
+(BOOL)fileExistsAtAbsolutePath:(NSString*)filename { BOOL isDirectory; BOOL fileExistsAtPath = [[NSFileManager defaultManager] fileExistsAtPath:filename isDirectory:&isDirectory]; return fileExistsAtPath && !isDirectory; }
Checking for directory existence:
+(BOOL)directoryExistsAtAbsolutePath:(NSString*)filename { BOOL isDirectory; BOOL fileExistsAtPath = [[NSFileManager defaultManager] fileExistsAtPath:filename isDirectory:&isDirectory]; return fileExistsAtPath && isDirectory; }