假设我的 iPhone 应用程序的“资源”文件夹中有一个名为“文档”的文件夹。
有没有一种方法可以在运行时获取该文件夹中包含的所有文件的数组或某种类型的列表?
所以,在代码中,它看起来像:
NSMutableArray *myFiles = [...get a list of files in Resources/Documents...];
这可能吗?
您可以获取到的路径Resources
像这样的目录,
NSString * resourcePath = [[NSBundle mainBundle] resourcePath];
然后附加Documents
到路径,
NSString * documentsPath = [resourcePath stringByAppendingPathComponent:@"Documents"];
然后你可以使用任何目录列表APINSFileManager
.
NSError * error;
NSArray * directoryContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:documentsPath error:&error];
Note:将源文件夹添加到捆绑包中时,请确保选择“复制时为任何添加的文件夹选项创建文件夹引用”
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)