如何从我的iPhone App文档目录中选择所有图像
问题描述:
我有一个包含一堆图像的文件夹.我想将所有图像的名称添加到数组中.图像位于应用程序上我文档的文件夹中.参见屏幕截图.
I have a folder containing a bunch of images. I would like to add the names of all the images to an array. The images are in a folder in my document on the app. See screen shot.
我知道,如果我想获得其中一张图像,我将使用以下代码.
I know If I would like to get one of these images I would use the following code.
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [NSString stringWithFormat:@"%@/POIs/%@", documentsDirectory,image];
是否可以选择文件夹中的所有文件?如果可以的话,是否还可以选择文件名并将它们添加到数组中?
Is it posible to select all the files in the folder? If it is would it also be possible to select the names of the files and add them to an array?
谢谢
答
获取POS文件夹的文件路径:
Get the file path of the POS folder:
NSString *filePath = [NSString stringWithFormat:@"%@/POIs", documentsDirectory];
然后执行:
NSArray *files = [fileManager contentsOfDirectoryAtPath:filePath
error:nil];
代码未经测试