Dr.*_*eon 2 macos cocoa objective-c
好的,基本上这就是我想做的事情:
myData(请注意:子文件夹/等中有很多文件/文件夹)你会怎么做?有任何想法吗?
PS
NSFileWrapper的writeFile:atomically:updateFilenames,但它不会让我访问每个文件使用Grand Central Dispatch(GCD)在异步线程中使用运行方法
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
// user disk space - will use user document
NSString *docuemntPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
// app bundle folder
NSString *bundleRoot = [[NSBundle mainBundle] resourcePath];
NSString *folderPath = [bundleRoot stringByAppendingPathComponent:@"aFolder"];
NSArray *files = [[NSFileManager defaultManager] enumeratorAtPath:folderPath].allObjects;
for (NSString *aFile in [files objectEnumerator]) {
NSString *copyPath = [folderPath stringByAppendingPathComponent:aFile];
NSString *destPath = [docuemntPath stringByAppendingPathComponent:aFile];
NSError *error;
if ([[NSFileManager defaultManager] copyItemAtPath:copyPath toPath:destPath error:&error]) {
NSLog(@"Copying successful");
// here add a percent to progress view
} else {
NSLog(@"Copying error: %@", error.userInfo);
}
}
// When the copying is finished update your UI
// on the main thread and do what ever you need with the object
dispatch_async(dispatch_get_main_queue(), ^{
[self someMethod:myData];
});
});
Run Code Online (Sandbox Code Playgroud)
并在您的主线程上使用UIProgressView从文件/文件夹的数量指示文件操作的进度.
| 归档时间: |
|
| 查看次数: |
372 次 |
| 最近记录: |