Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- dispatch_group_t readingGroup = dispatch_group_create();
- NSFileManager* manager = [NSFileManager defaultManager];
- NSString *docsDir = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Data"];
- NSDirectoryEnumerator *dirEnumerator = [manager enumeratorAtURL:[NSURL fileURLWithPath:docsDir]
- includingPropertiesForKeys:[NSArray arrayWithObjects:NSURLNameKey,
- NSURLIsDirectoryKey,nil]
- options:NSDirectoryEnumerationSkipsHiddenFiles
- errorHandler:nil];
- // An array to store the all the enumerated file names in
- NSMutableArray *arrayFiles;
- // Enumerate the dirEnumerator results, each value is stored in allURLs
- for (NSURL *url in dirEnumerator) {
- // Retrieve the file name. From NSURLNameKey, cached during the enumeration.
- NSString *fileName;
- [url getResourceValue:&fileName forKey:NSURLNameKey error:NULL];
- // Retrieve whether a directory. From NSURLIsDirectoryKey, also cached during the enumeration.
- NSNumber *isDirectory;
- [url getResourceValue:&isDirectory forKey:NSURLIsDirectoryKey error:NULL];
- if (![isDirectory boolValue]) {
- dispatch_group_enter(readingGroup);
- TWReaderDocument* doc = [TWReaderDocument documentFileURL:url withCompletionBlock:^(BOOL success) {
- dispatch_group_leave(readingGroup);
- }];
- [arrayFiles addObject:doc];
- }
- else if ([[[fileName componentsSeparatedByString:@"_" ] objectAtIndex:0] isEqualToString:@"ThalesData"]) {
- TreeItem* treeItem = [[TreeItem alloc] init];
- arrayFiles = [NSMutableArray arrayWithCapacity:10];
- treeItem.child = arrayFiles;
- treeItem.nodeName = [[fileName componentsSeparatedByString:@"_" ] lastObject];
- [self addItem:treeItem];
- }
- }
- dispatch_group_notify(readingGroup, dispatch_get_main_queue(), ^{ // 4
- NSLog(@"All concurrent tasks completed");
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement