我有几个图像在“ProjectImages”文件夹中,并希望从上述文件夹中检索图像文件名并将其存储在数组中,然后我想提取这些图像的扩展名文件并将其存储在另一个阵列中。我能够从文件夹中检索图像文件名并提取扩展名,但我不知道如何将提取的文件名存储在另一个数组中。下面是代码提取扩展名并保存图像名称
//get image name from the folder
NSError *error;
NSFileManager *fileMgr = [NSFileManager defaultManager];
NSString *directory = [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:@"ProjectImages"];
NSArray *files=[fileMgr contentsOfDirectoryAtPath:directory error:&error];
//extract the extension
NSString *imageNames=nil;
for (NSString *name in files) {
if (!imageNames) imageNames = [[name lastPathComponent] stringByDeletingPathExtension];
else imageNames = [imageNames stringByAppendingFormat:@" %@",[[name lastPathComponent] stringByDeletingPathExtension]];
}
NSLog(@"%@",imageNames); --> This returns one single name with all the image name, which i don't want, instead i want to store each extracted file name in array and wanted to compare the string entered by the user with this array. how to do it ?
你不存储任何数组中的任何。您正在构建一个空格分隔的文件名字符串。 – rmaddy 2015-02-10 20:01:51