zoukankan      html  css  js  c++  java
  • 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];
  • 相关阅读:
    「SHOI2015」脑洞治疗仪
    LOJ 数列分块入门 8
    CF932F Escape Through Leaf
    NOIP2021游记总结
    [HEOI2016/TJOI2016]序列
    【模板】动态树(Link Cut Tree)
    LG P2839 [国家集训队]middle
    JZOJ 7377.欢乐豆
    JZOJ 7392. 【2021.11.17NOIP提高组联考】数 (ds)
    LOJ 数列分块入门 6
  • 原文地址:https://www.cnblogs.com/AbelChen1991/p/3669246.html
Copyright © 2011-2022 走看看