我将图像文件存储在缓存目录中。稍后,我想从缓存目录中获取所有图像文件列表。我正在使用以下代码来获取所有文件。
[fileManager contentsOfDirectoryAtPath:pathForCacheDirectory error:&error]
如何从中分离图像文件。图像文件可以是任何格式。
提前致谢。
最佳答案
// Store your supported image Extensions
NSArray *extensionList = [NSArray arrayWithObjects:@"jpg", @"jpeg", @"png", @"gif", @"bmp", nil];
// Grab the content Directory
NSArray *contents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:pathForCacheDirectory error:&error];
NSMutableArray *listOfImageFiles = [NSMutableArray arrayWithCapacity:0];
// Check for Images of supported type
for(NSString *filepath in contents){
if ([extensionList containsObject:[filepath pathExtension]])
{
// Found Image File
[listOfImageFiles addObject:filepath];
}
}
NSLog(@"Lisf of Image Files : %@",listOfImageFiles);
关于iphone - 仅从目录获取图像文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15563714/