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];

  • 相关阅读:
    汉明距离
    Go_go build 和 go install
    rabbitmq的简单介绍二
    rabbitmq的简单介绍一
    redis的订阅和发布
    python操作redis
    vmware虚拟机开机报附件中的错误的解决办法
    使用twised实现一个EchoServer
    python事件驱动的小例子
    mysql数据库的最基本的命令
  • 原文地址:https://www.cnblogs.com/mfrbuaa/p/3759133.html
Copyright © 2011-2022 走看看