快速迭代文件剪切
- (void)apply
{
dispatch_queue_t queue = dispatch_get_global_queue(0, 0);
NSString *from = @"剪切前的路径";
NSString *to = @"剪切后的路径";
NSFileManager *manager = [NSFileManager defaultManager];
NSArray *subpaths = [manager subpathsAtPath:from];
// GCD的快速迭代,也可用for循环代替,但是效率比for快
dispatch_apply(subpaths.count, queue, ^(size_t index) {
NSString *subpath = subpaths[index];
NSString *fromFullPath = [from stringByAppendingPathComponent:subpath];
NSString *toFullPath = [to stringByAppendingPathComponent:subpath];
// 剪切
[manager moveItemAtPath:fromFullPath toPath:toFullPath error:nil];
});
}