iphone - 获取 Resources 文件夹中的文件列表 - iOS

标签 iphone ios resources

假设我的 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/

相关文章:

iphone - iPhone 中的资源包

c# - wpf 图像资源和在运行时在 wpf 控件中更改图像

ios - 在 Swift iPhone 应用程序中请求 SOAP Web 服务时 XMLStreamreader 错误

iphone - iOS 在另一个 uiview 中加载 uiview

objective-c - AFNetworking 中的 registerHTTPOperationClass 实际上做了什么?

ios - 应用程序会丢失无线安装的 NSUserDefault 数据吗?

c# - MonoTouch 的性能问题?

iphone - 底部按钮未显示在 iOS 模拟器中

ios - dateFromString 无法在设置为 24 小时 swift 的 Iphone 上转换

localization - Vala、资源和本地化