常见的NSFileManager方法

常见NSFileManager文件方法

-(NSData *)contentsAtPath:path

path所代表的文件中读取数据

-(BOOL)createFileAtPath:path contents:(BOOL)data attributes:attr

将数据写入文件

-(BOOL)removeFileAtPath:path handler:handler

path所代表的文件删除

-(BOOL)movePath:from toPath:to handler:handler

移动或者重命名文件,to所代表的文件不能是已经存在的文件

-(BOOL)copyPath:from toPath:to handler:handler

复制文件,to所代表的文件不能是已经存在的文件

-(BOOL)contentsEqualAtPath:path1 andPath:path2

比较path1path2所代表的文件

-(BOOL)fileExistsAtPath:path

检查path所代表的文件是否存在

-(BOOL)isReadableFileAtPath:path

检查path所代表的文件是否存在、是否可读

-(BOOL)isWritableFileAtPath:path

检查path所代表的文件是否存在、是否可写

-(NSDictionary *)fileAttributesAtPath:path traverseLink:(BOOL)flag

获取path所代表的文件属性

-(BOOL)changeFileAttributes:attr atPath:path

改变文件属性


常见的NSFileManager目录的方法:

-NSString *currentDirectoryPath 

获取当前目录

-BOOLchangeCurrentDirectoryPathpath

更改当前目录

-BOOLcopyPathfrom toPathto handlerhandler 

复制目录结构,to不能已经存在

-BOOLcreateDirectoryAtPathpath attributesattr

创建目录

-BOOLfileExistsAtPathpath isDirectory:(BOOL *flag 

测试文件是否为目录 (flag存储结构yes/no

-NSArray *contentsOfDirectoryAtPath:path 

列出目录的内容

-NSDirectoryEnumerator *enumeratorAtPathpath 

枚举目录的内容

-BOOLremoveFileAtPathpath handlerhandler 

删除空目录

-BOOLmovePath:from toPath:tohandler:handler

重命名或移动一个目录,to不能是已经存在的

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值