• 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];
  • 相关阅读:
    C 实战练习题目45
    C 实战练习题目44
    C 实战练习题目43
    C 实战练习题目42 -auto定义变量
    C 实战练习题目41 -static定义静态变量
    如何0基础学习C/C++?
    2019-11-29-win10-uwp-关联文件
    2019-11-29-win10-UWP-Controls-by-function
    2019-11-29-WPF-高性能笔
    2019-11-29-WPF-使用-Win2d-渲染
  • 原文地址:https://www.cnblogs.com/AbelChen1991/p/3669246.html
Copyright © 2020-2023  润新知