帮助:列出iPhone应用程序包子路径的内容?

帮助:列出iPhone应用程序包子路径的内容?,iphone,Iphone,我正在尝试获取包含在我的应用程序包的子路径中的目录列表。我做了一些搜索,这就是我想到的 - (void) contents { NSArray *contents = [[NSBundle mainBundle] pathsForResourcesOfType:nil inDirectory:@"DataDir"]; if (contents = nil) { NSLog(@"Failed: p

我正在尝试获取包含在我的应用程序包的子路径中的目录列表。我做了一些搜索,这就是我想到的

- (void) contents {
 NSArray *contents = [[NSBundle mainBundle] pathsForResourcesOfType:nil
                                               inDirectory:@"DataDir"];
 if (contents = nil) {
  NSLog(@"Failed: path doesn't exist or error!");
 } else {
     NSString *bundlePathName = [[NSBundle mainBundle] bundlePath];
  NSString *dataPathName = [bundlePathName stringByAppendingPathComponent:
                                 @"DataDir"];
     NSFileManager *fileManager = [NSFileManager defaultManager];

     NSMutableArray *directories = [[NSMutableArray alloc] init];
     for (NSString *entityName in contents) {
            NSString *fullEntityName = [dataPathName
                                       stringByAppendingPathComponent:entityName];
            NSLog(@"entity = %@", fullEntityName);
            BOOL isDir = NO;
            [fileManager fileExistsAtPath:fullEntityName isDirectory:(&isDir)];
            if (isDir) {
                [directories addObject:fullEntityName];
                NSLog(@" is a directory");
            } else {
                NSLog(@" is not a directory");
            }
        }
        NSLog(@"Directories = %@", directories);

        [directories release];
 }
}
如您所见,我正在尝试获取应用程序包的DataDir子路径中的目录列表。问题是我的内容中没有字符串

注:
-我正在使用模拟器
-当我手动查看.app文件时,我可以看到DataDir及其内容
-DataDir的内容是png文件和包含png文件的目录
-应用程序逻辑需要在运行时发现DataDir的内容
-我也尝试过使用

 NSArray *contents = [fileManager contentsOfDirectoryAtPath:DataDirPathName error:nil];
我的内容数组中仍然没有条目

有什么建议/替代方法吗


谢谢

我不确定我昨天做错了什么,但我有以下代码:

NSString *bundlePathName = [[NSBundle mainBundle] bundlePath];
NSString *dataPathName = [bundlePathName stringByAppendingPathComponent:@"DataDir"];
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);
    }