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];
  • 相关阅读:
    Linux下的CPU使用率与服务器负载的关系与区别
    zabbix修改Template OS Linux模版使已使用内存(Used memory)更准确
    mysql查询时间戳和日期的转换
    python logging模块
    网络编程(TCP)
    网络编程(UDP)
    计算机网络
    IO流(字符流)
    IO流(字节流)
    算法
  • 原文地址:https://www.cnblogs.com/AbelChen1991/p/3669246.html
Copyright © 2011-2022 走看看