繁体   English   中英

如何按文件夹获取pdf文件列表?

[英]How to get the pdf file lists folder by folder?

现在,我目前正在使用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文件夹,并将其存储在单独的数组中,我的文件夹结构如下图所示,

在此处输入图片说明

关于此的任何帮助将不胜感激。

在此处输入图片说明

为此,您可以创建捆绑软件而不是文件夹,然后将其中的所有捆绑软件和文件

像这样的东西

NSArray *bundleArr = [[NSBundle mainBundle]pathsForResourcesOfType:@"bundle" inDirectory:nil];
NSLog(@"pdfs in bundle %@ is my class is %@",[bundleArr objectAtIndex:0],[[bundleArr objectAtIndex:0]class]);


for (int i=0; i<[bundleArr count]; i++) {
    NSString *myBundleStr=[bundleArr objectAtIndex:i];
    NSBundle *myBundle = [[NSBundle alloc]initWithPath:[bundleArr objectAtIndex:i]];
    NSArray *pdfPaths = [myBundle pathsForResourcesOfType:@"pdf" inDirectory:nil];
    NSLog(@"\n\nPDF in bundle  is %@",pdfPaths);

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM