如何获取Documents目录中文件的所有路径? [英] How to get All paths for files in Documents directory?
本文介绍了如何获取Documents目录中文件的所有路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我通常使用 NSBundle
来获取路径。
I usually get paths by using NSBundle
.
但是, NSBundle
不包含Documents文件夹。
But, NSBundle
does not contain Documents folder.
如何获取Documents目录中文件的所有路径(或名称)?
How to get All paths(or names) for files in Documents directory?
推荐答案
这将为你提供文件目录下所有文件的路径
This will give u the paths for all files under documents directory
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSArray *filePathsArray = [[NSFileManager defaultManager] subpathsOfDirectoryAtPath:documentsDirectory error:nil];
NSLog(@"files array %@", filePathsArray);
您可以使用以下代码获取filePathsArray中每个对象的路径
You can get the path for each object in filePathsArray by using the below code
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:[filePathsArray objectAtIndex:0]];
这篇关于如何获取Documents目录中文件的所有路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文