文件大小的计算和文件夹大小的计算

1读取本地documents文件里文件夹的大小(我们可以利用NSDirectoryEnumerator这个类)

      NSString * Docupath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];

                //    一般不要吧文件直接放到documents文件夹下,要创建新的文件夹

                NSString * filePath = [Docupath stringByAppendingPathComponent:@"DownLoadFile"];

                NSDirectoryEnumerator * enumerator = [[NSFileManager defaultManager] enumeratorAtPath:filePath];

                long long size = 0;

                while ([enumerator nextObject])

                {

                    NSDictionary * dic = [enumerator fileAttributes];

                    size += [dic fileSize];

                }

2.获取文件夹的属性使用

  [[NSFileManager defaultManager] attributesOfItemAtPath:[filePath] error:nil];

它仅仅能查询到文件夹的属性不能计算文件夹的大小

3.计算文件下载的大小

  NSDictionary * info = [[NSFileManager defaultManager] attributesOfItemAtPath:path error:nil];

      long long size =  [info fileSize];

4.从单元格上删除本地问件和从单元格上删除

   Pub_file * p = self.ReceiveArry[indexPath.row]; 

 //    从本地删除

    [[NSFileManager defaultManager] removeItemAtPath:[filedownload CreatPath:p.name] error:nil];

//    从表格上删除

    [self.ReceiveArry removeObjectAtIndex:indexPath.row];

    [_TableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];

从本地删除文件科技直接利用文件管理器直接删除,,,,,,,,删除单元格上内容时必须先源数组里的内容删除,然后把此内容所对应的单元格删除,否则会造成程序崩溃

转载于:https://www.cnblogs.com/wangzhen-Me/p/4884818.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值