现在我正在开发 pdf 阅读器应用程序,我可以使用以下代码读取应用程序中存在的所有 pdf 文件,
NSArray *userDocuments = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSURL *docementsURL = [NSURL fileURLWithPath:[userDocuments lastObject]];
NSArray *documentsURLs = [[NSFileManager defaultManager] contentsOfDirectoryAtURL:docementsURL
includingPropertiesForKeys:nil
options:NSDirectoryEnumerationSkipsHiddenFiles
error:nil];
NSMutableArray *names = [NSMutableArray array];
NSMutableDictionary *urls = [NSMutableDictionary dictionary];
NSArray *bundledResources = [[NSBundle mainBundle] URLsForResourcesWithExtension:@"pdf" subdirectory:nil];
documentsURLs = [documentsURLs arrayByAddingObjectsFromArray:bundledResources];
for (NSURL *docURL in documentsURLs)
{
NSString *title = [[docURL lastPathComponent] stringByDeletingPathExtension];
[names addObject:title];
[urls setObject:docURL forKey:title];
}
documents = [[NSArray alloc] initWithArray:[names sortedArrayUsingSelector:@selector(compare:)]];
urlsByName = [[NSDictionary alloc] initWithDictionary:urls];
但我的问题是逐个文件夹读取pdf文件并将其存储到单独的数组中,我的文件夹结构如下图所示,
任何有关此的帮助将不胜感激..