zoukankan      html  css  js  c++  java
  • ios 得到目录大小 进率是1000

    - (CGFloat)folderSizeAtPath:(NSString *) folderPath
    {
        NSFileManager * manager = [NSFileManager defaultManager];
        
        if (![manager fileExistsAtPath:folderPath])
        {
          return 0;
        }
        
        NSEnumerator * childFilesEnumerator = [[manager subpathsAtPath:folderPath] objectEnumerator];
        NSString * fileName;

        long long folderSize = 0;
        
        while ((fileName = [childFilesEnumerator nextObject]) != nil)
        {
            
            NSString * fileAbsolutePath = [folderPath stringByAppendingPathComponent:fileName];
            
            float singleFileSize = 0.0;
            if ([manager fileExistsAtPath:fileAbsolutePath])
            {
                singleFileSize = [[manager attributesOfItemAtPath:fileAbsolutePath error:nil] fileSize];
                NSLog(@"singleFileSize %f",singleFileSize);
            }
            folderSize += singleFileSize;
        
        }
        NSLog(@"count file size %f",folderSize/1000.0);
        return folderSize/1000.0;
        

    }


    调用 :


        NSString * filePath = [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:[NSString stringWithFormat:@"/%@",@"TencentOpenApi_IOS_Bundle.bundle"]];
        
        [self folderSizeAtPath:filePath];

  • 相关阅读:
    java学习--工具类学习之Arrays(1)
    509. 斐波那契数
    572. 另一个树的子树
    cmd中的标准文件重定向
    ng正则使用(持续更新)
    MySQL基准测试
    mysql_connect 弃用之后使用mysqli替换需要注意事项
    数据迁移到rds时候犯下的低级错误
    MySQL 架构与历史
    mysql中涉及到钱的字段如何设计
  • 原文地址:https://www.cnblogs.com/mfrbuaa/p/3759133.html
Copyright © 2011-2022 走看看