You need to use the NSFileManager contentsOfDirectoryAtPath:error: function. Please note that this does not cross subdirectories, and extension cannot contain . .
-(NSArray *)findFiles:(NSString *)extension { NSMutableArray *matches = [[NSMutableArray alloc]init]; NSFileManager *manager = [NSFileManager defaultManager]; NSString *item; NSArray *contents = [manager contentsOfDirectoryAtPath:[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] error:nil]; for (item in contents) { if ([[item pathExtension]isEqualToString:extension]) { [matches addObject:item]; } } return matches; }
source share