8
我在我的資源文件夾做文件夾結構,就像...資源=>邁德特=> S1 然後在S1 => Name.png,data.ppt如何從iPhone資源文件夾中獲取文件夾和文件的列表?
現在,我想所有的文件夾列表和文件名。這裏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);
}
感謝,