![](/img/trans.png)
[英]How to copy items from Documents directory to .app directory in iPhone App?
[英]How to get the directory tree of iPhone App Documents Directory
在我的App中,我在“文档”下创建了子文件夹,在子文件夹下创建了子文件夹。 因此,有一个文档树。 我希望以一种能够在表视图中列出它们的方式来获取树。 它们看起来像下面的线性清单,带有不同的缩进量以显示其级别。
当我尝试使用while循环和for循环进行此操作时,我不确定是否有一些方便的方法来完成此操作。
感谢您的建议。
谢谢。
Apple提供了许多用于文件系统访问的类,甚至还提供了一些您尝试执行的递归类。
我建议您看一下《 Apple File System编程指南》和NSFileManager
类文档 。 此外, NSDirectoryEnumerator
类也可能会有所帮助。
我不知道如何一次获得整个层次结构。 但是以下方法可能会有所帮助。
1用它来存放文件。
NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
NSString * documentPath = [路径objectAtIndex:0];
2使用- (NSArray *)contentsOfDirectoryAtPath:(NSString )path error:(NSError * )error
获取文档目录中的目录列表。
阅读此类参考以获取更多详细信息。
3使用以下方法可以创建内部目录的路径。
NSString * directoryPath = [documentPath stringByAppendingPathComponent:[MAIN_DIRECTORY stringByAppendingPathComponent:filePath]];
结合使用以上三个可以浏览文件目录的内容。
希望这会有所帮助
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
和
NSFileManager *manager = [NSFileManager defaultManager];
NSArray *fileList = [manager directoryContentsAtPath:documentsDirectory];
for (NSString *s in fileList){
NSLog(s);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.