[英]How to set NSURL Resource Values for all files and folders within a folder
[英]How get list of folders and files from resource folder in 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];
然后将Documents
附加到路径,
NSString * documentsPath = [resourcePath stringByAppendingPathComponent:@"Documents"];
然后,您可以使用NSFileManager
任何目录列表API。
NSError * error;
NSArray * directoryContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:documentsPath error:&error];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.