#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
[self MoveFileApply];
}
-(void)MoveFile
{
//1.要剪切的文件夹路径
NSString *from = @"/Users/a1/Desktop/from";
//2.目标文件夹的路径
NSString *to = @"/Users/a1/Desktop/to";
//3.文件管理者
NSFileManager *manager = [NSFileManager defaultManager];
NSArray *subPaths = [manager subpathsAtPath:from];
NSLog(@"%@",subPaths);
//4.遍历文件并执行剪切文件的操作
NSInteger count = subPaths.count;
for (NSInteger i = 0; i<count; i++) {
//4.0 文件的名称
NSString *fileName = subPaths[i];
//4.1 拼接文件的全路径
NSString *subPath = [from stringByAppendingPathComponent:fileName];
// /Users/a1/Desktop/from/Snip20151124_16.png
//4.2 应该剪切到什么地方去
NSString *fullPath = [to stringByAppendingPathComponent:fileName];
// /Users/a1/Desktop/to/Snip20151124_16.png
//4.3 执行剪切
/*
第一个参数:在什么地方
第二个参数:要移到哪里
第三个参数:nil
*/
[manager moveItemAtPath:subPath toPath:fullPath error:nil];
NSLog(@"%@--%@,%@",subPath,fullPath,[NSThread currentThread]);
}
}
-(void)MoveFileApply
{
//1.要剪切的文件夹路径
NSString *from = @"/Users/a1/Desktop/from";
//2.目标文件夹的路径
NSString *to = @"/Users/a1/Desktop/to";
//3.文件管理者
NSFileManager *manager = [NSFileManager defaultManager];
NSArray *subPaths = [manager subpathsAtPath:from];
NSLog(@"%@",subPaths);
//4.遍历文件并执行剪切文件的操作
NSInteger count = subPaths.count;
dispatch_apply(count, dispatch_get_global_queue(0, 0), ^(size_t index) {
//4.0 文件的名称
NSString *fileName = subPaths[index];
//4.1 拼接文件的全路径
NSString *subPath = [from stringByAppendingPathComponent:fileName];
// /Users/a1/Desktop/from/Snip20151124_16.png
//4.2 应该剪切到什么地方去
NSString *fullPath = [to stringByAppendingPathComponent:fileName];
// /Users/a1/Desktop/to/Snip20151124_16.png
//4.3 执行剪切
/*
第一个参数:在什么地方
第二个参数:要移到哪里
第三个参数:nil
*/
[manager moveItemAtPath:subPath toPath:fullPath error:nil];
NSLog(@"%@--%@,%@",subPath,fullPath,[NSThread currentThread]);
});
}
-(void)test
{
//迭代
/*
for (NSInteger i = 0; i<10; i++) {
NSLog(@"%zd---%@",i,[NSThread currentThread]);
}
*/
//GCD中快速迭代
/*
第一个参数:要遍历的次数
第二个参数:队列(并发
第三个参数:size_t 索引
*/
dispatch_apply(10, dispatch_get_global_queue(0, 0), ^(size_t index) {
NSLog(@"%zd---%@",index,[NSThread currentThread]);
});
}
@end