获取Resources文件夹中的文件列表 - iOS [英] Getting a list of files in the Resources folder - iOS
问题描述
假设我的iPhone应用程序的Resources文件夹中有一个名为Documents的文件夹。
Let's say I have a folder in my "Resources" folder of my iPhone application called "Documents".
有没有办法可以获得数组或运行时该文件夹中包含的所有文件的某种类型的列表?
Is there a way that I can get an array or some type of list of all the files included in that folder at run time?
因此,在代码中,它看起来像:
So, in code, it would look like:
NSMutableArray *myFiles = [...get a list of files in Resources/Documents...];
这可能吗?
推荐答案
你可以像这样获得 Resources
目录的路径,
You can get the path to the Resources
directory like this,
NSString * resourcePath = [[NSBundle mainBundle] resourcePath];
然后将 Documents
附加到路径中,
Then append the Documents
to the path,
NSString * documentsPath = [resourcePath stringByAppendingPathComponent:@"Documents"];
然后你可以使用 NSFileManager的任何目录列表API
。
NSError * error;
NSArray * directoryContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:documentsPath error:&error];
注意:在源文件夹中添加源文件夹时,请确保选择复制
Note : When adding source folder into the bundle make sure you select "Create folder references for any added folders option when copying"
这篇关于获取Resources文件夹中的文件列表 - iOS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!