iphone - 仅从目录获取图像文件

标签 iphone ios objective-c

我将图像文件存储在缓存目录中。稍后,我想从缓存目录中获取所有图像文件列表。我正在使用以下代码来获取所有文件。

[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/

相关文章:

ios - SpriteKit + Swift 中的多点触控手势识别

c++ - 为什么我的 CFRunLoopTimer 没有触发?

ios - iOS 应用的动态内容

iphone - 制作 UIButton 复选框的最佳方法是什么?

iphone - DB Wrapper 不响应消息?

html - 单选按钮在 iPad 上显示不正确

iphone - iOS 7 中的转弯导航

iphone - 三20 “pull down to update” : How to change the text and datetime format?

ios - 以多种方式通过 RACSignal 设置按钮的启用属性?

iphone - 通过 ASIHTTP 请求并行下载文件的最大数量