假设我在iPhone应用程序的"Resources"文件夹中有一个名为"Documents"的文件夹.
有没有办法在运行时获取该文件夹中包含的所有文件的数组或某种类型的列表?
因此,在代码中,它看起来如下所示:
NSMutableArray *myFiles = [...get a list of files in Resources/Documents...];
这个是可能的吗?
假设我在iPhone应用程序的"Resources"文件夹中有一个名为"Documents"的文件夹.
有没有办法在运行时获取该文件夹中包含的所有文件的数组或某种类型的列表?
因此,在代码中,它看起来如下所示:
NSMutableArray *myFiles = [...get a list of files in Resources/Documents...];
这个是可能的吗?
您可以像这样获得Resources
目录的路径,
NSString * resourcePath = [[NSBundle mainBundle] resourcePath];
然后将Documents
添加到路径,
NSString * documentsPath = [resourcePath stringByAppendingPathComponent:@"Documents"];
然后,您可以使用NSFileManager
的任何目录列表API.
NSError * error;
NSArray * directoryContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:documentsPath error:&error];
Note:将源文件夹添加到包中时,请确保 Select "复制时为任何添加的文件夹创建文件夹引用"选项