星空网 > 软件开发 > 操作系统

文件内存空间大小计算

/**

         *  要求计算一个文件中所有文件的大小

         注意:必须先计算一个文件夹中所有文件的大小必须先拿到所有文件,然后再获取所有文件的大小,然后相加

         */

        NSFileManager *manager=[NSFileManager defaultManager];

        //提取要求计算的文件

        NSArray *arr=[manager subpathsAtPath:@"/Users/zhangyunjiang/Desktop"];

        NSMutableString *strM=[NSMutableString string];

        NSMutableString *strM1=[NSMutableString string];

        for (int i=0; i<arr.count; i++) {

            //将文件中所有文件名添加到字符串

            [strM appendFormat:@"////Users/zhangyunjiang/Desktop/%@",arr[i]];

        }

        //将添加文件名的字符串转变成为数组

        NSArray *arr1=[strM componentsSeparatedByString:@"///"];

        for (int j=0; j<arr.count; j++) {

            //从数组中提取每一个文件名的属性内容

            NSDictionary *dic=[manager attributesOfItemAtPath:(arr1[j]) error:nil];

            //查找内容中文件所占内存大小

            NSString *str3=dic[NSFileSize];

            [strM1 appendFormat:@"-%@",str3];

            

        }

        //进行计算

        NSArray *arr2=[strM1 componentsSeparatedByString:@"-"];

        double sum=0;

        for (int i=0; i<arr2.count; i++) {

            NSString *str3=[arr2 objectAtIndex:i];

            if (str3==nil) {

                

            }

            else

            {

                sum+=[str3 intValue];

            }

        }

        //将空间转换成为GM

        double  newsum=sum/1024/1024/1024;

        NSLog(@"%f",sum);

        NSLog(@"%f",newsum);

    }

    return 0;

 




原标题:文件内存空间大小计算

关键词:内存

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

加拿大专线货代:https://www.goluckyvip.com/tag/34519.html
加拿大专线空运:https://www.goluckyvip.com/tag/34520.html
加拿大专线快递:https://www.goluckyvip.com/tag/34521.html
加纳海外仓:https://www.goluckyvip.com/tag/34522.html
加州65测试:https://www.goluckyvip.com/tag/34523.html
加州纾困金计划:https://www.goluckyvip.com/tag/34524.html
长治婚庆女司仪和主持人:https://www.vstour.cn/a/366176.html
北京丰台区水上乐园哪家好玩?:https://www.vstour.cn/a/366177.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流