8
私は私のリソースフォルダ内のフォルダ構造をしていますように...リソース=>のMyData => S1 その後、S1 => Name.png、data.pptiPhoneのリソースフォルダからフォルダとファイルのリストを取得するにはどうすればよいですか?
に今、私はすべてのフォルダリストとファイル名を取得したいです。ここでMyDataの名前は静的な他のものに変更されることがあります.S1、S2、S3、およびその中のファイルの数を追加することができます。どのようにObjective Cを通じてこれらのコンテンツを読むのですか?私は以下のコードを試しました。あなたはこのようなResources
ディレクトリへのパスを取得することができ
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);
}
おかげで、