zoukankan      html  css  js  c++  java
  • IOS中级篇 —— NSFileManager常用方法

    [fileManager isDeletableFileAtPath:<#(NSString *)#>]; 判断一个路径是否可删除
    [fileManager isWritableFileAtPath:<#(NSString *)#>];  判断一个路径是否可写
    [fileManager isReadableFileAtPath:<#(NSString *)#>];  判断一个路径是否可读
    [fileManager fileExistsAtPath:<#(NSString *)#>];    判断一个路径是否存在
    [fileManager fileExistsAtPath:<#(NSString *)#> isDirectory:<#(BOOL *)#>]; 判断一个路径是否是一个文件夹   bool需要传进  返回的值存在bool中
    [fileManager attributesOfItemAtPath:<#(NSString *)#> error:<#(NSError *__autoreleasing *)#>];  显示详细信息
     
     获取文件夹下的所以文件   递归
     

    [fileManager subpathsAtPath:path];

    [fileManager subpathsOfDirectoryAtPath:path error:&error];

    - (NSArray *)subpathsOfDirectoryAtPath:(NSString *)path error:(NSError **)error;   非递归

    获取文件夹下的文件夹
    [fileManger contentsOfDirectoryAtPath:path error:&err (error:nil)]

     创建文件夹

    [fileManager createDirectoryAtPath:path withIntermediateDirectories:NO attributes:nil error:nil];

    创建文件 事先需要一个NSData
    NSData *data = [str dataUsingEncoding:NSUTF8StringEncoding];
    [fileManager createFileAtPath:[NSString stringWithFormat:@"%@/1.txt",path] contents:data attributes:nil];
     
    文件拷贝  文件夹不存在刚会失败 不会新建文件夹
    [fileManager copyItemAtPath:[NSString stringWithFormat:@"%@/1.txt",path] toPath:[NSString stringWithFormat:@"%@/bbb/1.txt",path] error:nil];
     
    文件移动  文件夹不存在刚会失败 不会新建文件夹
    [fileManager moveItemAtPath:[NSString stringWithFormat:@"%@/1.txt",path] toPath:[NSString stringWithFormat:@"%@/ddd/1.txt",path] error:nil];
     
    文件移除
    [fileManager removeItemAtPath:[NSString stringWithFormat:@"%@/1.txt",path] error:nil];
  • 相关阅读:
    视觉三维重建中不同三角网格视角的选择
    最小二乘求解常数k使得kx=y(x,y为列向量)
    STL常用
    2D-2D:对极几何 基础矩阵F 本质矩阵E 单应矩阵H
    Ubuntu常用软件
    ubuntu linux 安装分区
    单向链表
    1.ssm web项目中的遇到的坑--自定义JQuery插件(slide menu)
    模板引擎freemarker的使用(二)
    模板引擎freemarker的使用(一)
  • 原文地址:https://www.cnblogs.com/deng1989/p/4595259.html
Copyright © 2011-2022 走看看