我正在资源文件夹中执行文件夹结构,例如... 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);
}
Thanks,
您可以获取到的路径Resources
像这样的目录,
NSString * resourcePath = [[NSBundle mainBundle] resourcePath];
然后附加Documents
到路径,
NSString * documentsPath = [resourcePath stringByAppendingPathComponent:@"Documents"];
然后你可以使用任何目录列表APINSFileManager
.
NSError * error;
NSArray * directoryContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:documentsPath error:&error];
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)