剪切文件

快速迭代文件剪切

- (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];
    });
}
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。