假设我的 iPhone 应用程序的“资源”文件夹中有一个名为“文档”的文件夹。
有没有办法在运行时获取该文件夹中包含的所有文件的数组或某种类型的列表?
所以,在代码中,它看起来像:
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];
注意:将源文件夹添加到包中时,确保选择“复制时为任何添加的文件夹选项创建文件夹引用”
关于iphone - 获取 Resources 文件夹中的文件列表 - iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6398937/