How to find multiple wildcard files in objective-c

How can I get all * .bmp files (or * .xyz in general) in the "Document" folder by writing the iPhone 3.0 SDK?

+1
source share
1 answer

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; } 
+3
source

All Articles