利用文件的路径来操作文件

1.利用NSFileManager 文件处理类来得到文件夹路径下的所有文件或文件夹名称

    NSFileManager *fm = [NSFileManager defaultManager];

//获取某个文件夹路径下面的所有的文件或文件夹名称

    NSString *path = @"/Users/tarena/Desktop/full";

    NSArray *fileNames = [fm contentsOfDirectoryAtPath:path error:nil];//获取在path这个文件夹下的内容目录

 //得到完整路径

    NSString *filePath = [path stringByAppendingPathComponent:fileName];

2.判断文件是否存在

    if ([fm fileExistsAtPath:path]) {

        NSLog(@"存在");

    }else{

        NSLog(@"不存在");

   }

3.判断这个文件是文件夹还是文件

BOOL isDirecoty = NO; //声明一个布尔变量

    if ([fm fileExistsAtPath:path isDirectory:&isDirecoty] && isDirecoty) {

        NSLog(@"是文件夹");

    }

4.删除文件

 [fm removeItemAtPath:filePath error:nil]

5.复制文件

[fm copyItemAtPath:filePath toPath:@"/Users/tarena/Desktop/day08/day08.zip" error:nil];

6.移动文件

[fm moveItemAtPath:filePath toPath:@"/Users/tarena/Desktop/day08/day08.zip" error:nil];



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值