HTML5   发布时间:2022-04-27  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了如何获取iPhone资源文件夹中的文件夹和文件列表?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我在我的资源文件夹中做文件夹结构,如… resource => MyData => S1
然后在S1 => Name.png,data.ppt

现在我想获取所有文件夹列表和文件名.这里MyData名称只是静态其他可能会改变.就像我可以添加S1,S2,S3和文件数量.那么如何通过Objective C阅读这些内容呢?我试过下面的代码.

NSString *bundlePathName = [[NSBundle mainBundle] bundlePath];
    NSString *dataPathName = [bundlePathName StringByAppendingPathComponent:@"resources"];
    NSFileManager *fileManager = [NSFileManager defaultManager];
    if ([fileManager fileExistsAtPath:dataPathName]) {
        NSLog(@"%@ exists",dataPathName);
        BOOL isDir = NO;
        [fileManager fileExistsAtPath:dataPathName isDirectory:(&isDir)];
        if (isDir == YES) {
            NSLog(@"%@ is a directory",dataPathName);
            NSArray *contents;
            contents = [fileManager contentsOfDirectoryAtPath:dataPathName error:nil];
            for (NSString *entity in contents) {
                NSLog(@"%@ is within",entity);
            }
        } else {
            NSLog(@"%@ is not a directory",dataPathName);
        }
    } else {
        NSLog(@"%@ does not exist",dataPathName);
    }

谢谢,

解决方法

您可以像这样获取resources目录的路径,

NSString * resourcePath = [[NSBundle mainBundle] resourcePath];

然后将文档附加到路径,

NSString * documentsPath = [resourcePath StringByAppendingPathComponent:@"Documents"];

然后,您可以使用NSFileManager的任何目录列表API.

NSError * error;
NSArray * directoryContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:documentsPath error:&error];

大佬总结

以上是大佬教程为你收集整理的如何获取iPhone资源文件夹中的文件夹和文件列表?全部内容,希望文章能够帮你解决如何获取iPhone资源文件夹中的文件夹和文件列表?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。