我可以列出Document Directory
中Table view
内的内容。但我有50个文件夹,我从文档目录中的各种来源下载。现在我想要获取所有50个文件夹内容以及文档目录内容...
//This is my Code...
NSArray * paths = NSSearchPathForDirectoriesInDomains ( NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSError * error;
NSArray *extensions = [NSArray arrayWithObjects:@"mp4", @"folder", @"mov", @"m4v", @"pdf", @"doc", @"xls", @"mp3" ,nil];
directoryContents = [[NSFileManager defaultManager]
contentsOfDirectoryAtPath:documentsDirectory error:&error];
directoryContents = [directoryContents filteredArrayUsingPredicate:
[NSPredicate predicateWithFormat:@"pathExtension IN %@", extensions ]];
NSLog(@"directoryContents ====== %@",directoryContents);
答案 0 :(得分:3)
test=[[NSMutableArray alloc]init];// allocate mutable array Globally
NSArray * paths = NSSearchPathForDirectoriesInDomains ( NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSDirectoryEnumerator *de = [[NSFileManager defaultManager] enumeratorAtPath:documentsDirectory] ;
NSString *file;
while ((file = [de nextObject]))
if (([[file pathExtension] isEqualToString:@"mp3"]) || ([[file pathExtension] isEqualToString:@"mp4"]) || ([[file pathExtension] isEqualToString:@"mov"]) || ([[file pathExtension] isEqualToString:@"avi"]) || ([[file pathExtension] isEqualToString:@"mkv"]))
[test addObject:file.lastPathComponent];
NSLog(@"%@",test);
//这将仅列出文件夹或子文件夹内的所有内容,但不列出文件夹。只需要在条件
中将字符串匹配传递给您的扩展名