如何从iPhone中的资源文件夹中获取文件夹和文件列表?

如何从iPhone中的资源文件夹中获取文件夹和文件列表?,iphone,objective-c,ios,ipad,Iphone,Objective C,Ios,Ipad,我正在做我的资源文件夹文件夹结构像。。。资源=>MyData=>S1 然后在S1=>Name.png,data.ppt中 现在我想得到所有文件夹列表和文件名。这里我的数据名是静态的,其他的可能会改变。比如我可以添加S1、S2、S3和其中的文件数。那么如何通过Objective C阅读这些内容呢?我尝试了下面的代码 NSString *bundlePathName = [[NSBundle mainBundle] bundlePath]; NSString *dataPathName =

我正在做我的资源文件夹文件夹结构像。。。资源=>MyData=>S1 然后在S1=>Name.png,data.ppt中

现在我想得到所有文件夹列表和文件名。这里我的数据名是静态的,其他的可能会改变。比如我可以添加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);
    }

谢谢,

您可以像这样获得
资源
目录的路径

NSString * resourcePath = [[NSBundle mainBundle] resourcePath];
然后将
文档
附加到路径

NSString * documentsPath = [resourcePath stringByAppendingPathComponent:@"Documents"];
然后,您可以使用
NSFileManager
的任何目录列表API

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