[英]iPhone SDK: How to copy the contents of a NSArray to NSMutable array?
[英]Copy contents of directory to an NSArray
我在名为Wallpaper的文件夹中有许多jpg格式的图像。 我正在尝试读取目录的内容,并使用以下代码将它们存储在数组中:
NSFileManager *manager = [NSFileManager defaultManager];
NSArray *fileList = [manager contentsOfDirectoryAtPath:@"/Wallpaper" error:NULL];
但它不起作用。 我无法将它们提取到阵列中。 谁能告诉我这是怎么了?
您需要指定目录的完整路径。 我假设您的文件夹Wallpaper
位于文档目录中。
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *extractDirPath = [documentsPath stringByAppendingString: @"/Wallpaper"];
NSArray *extractsList = [fileManager contentsOfDirectoryAtPath: extractDirPath error: nil];
您正在使用绝对路径“ / Wallpaper”,但是我想您的墙纸文件夹不在/?中。
NSArray *fileList = [manager contentsOfDirectoryAtPath:@"/Wallpaper" error:NULL];
并尝试这样:
NSError *error = nil;
NSArray *fileList = [manager contentsOfDirectoryAtPath:@"/Wallpaper" error:&error];
NSLog(@"load wallpaper error: %@", error);
这将为您提供实际发生的错误。
尝试这个:
NSFileManager *filemgr= [NSFileManager defaultManager];
NSArray *filelist = [filemgr contentsOfDirectoryAtPath:Pathwithfoldername error:nil];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.