NSFileManager学习创建拷贝删除

 NSFileManager * fm=[NSFileManager defaultManager];
       
        NSString * path=@"/Users/mac/Desktop";
        NSError * error=nil;
        //取得当前文件路径下地所有文件或者文件夹
        NSArray * array=[fm contentsOfDirectoryAtPath:path error:&error];
        //当前是浅度遍历
//        NSLog(@"%@",array);
        //深度遍历 当有文件夹的时候继续进去读取
        array =[fm subpathsOfDirectoryAtPath:path error:&error];
        //创建文件夹   参数1:文件夹的路径  参数2:是否创建中间目录,no的话会报错 正确应该填yes
        [fm createDirectoryAtPath:[NSString stringWithFormat:@"%@/dir/hello",path] withIntermediateDirectories:YES attributes:nil error:&error];
        if (error) {
            NSLog(@"%@",error);
            exit(-1);
        }
        //创建一个文件 参数1:文件的路径  参数2:内容  参数3:属性
        [fm createFileAtPath:[NSString stringWithFormat:@"%@/dir/hello/file",path] contents:[@"helel" dataUsingEncoding:NSUTF8StringEncoding]  attributes: nil];
    
        //删除一个文件夹或者文件
        [fm removeItemAtPath:[NSString stringWithFormat:@"%@/dir",path] error:nil];
        
        //copy 不分文件或者路径的
        [fm copyItemAtPath:@"之前的path" toPath:@"新的path" error:nil];
原文地址:https://www.cnblogs.com/AbelChen1991/p/3669246.html