//计算缓存大小
-(
NSString
*)getCacheSize{
//定义变量存储总的缓存大小
long long sumSize =
0
;
//获取当前图片缓存路径
NSString *cacheFilePath = [NSHomeDirectory()
stringByAppendingPathComponent:@"Library/Caches"
];
//创建文件管理对象
NSFileManager *filemanager = [NSFileManager
defaultManager
];
//获取当前缓存路径下的所有子路径
NSArray *subPaths = [filemanager
subpathsOfDirectoryAtPath:cacheFilePath error:nil
];
//遍历所有子文件
for (NSString *subPath
in
subPaths) {
//拼接完整路径
NSString *filePath = [cacheFilePath
stringByAppendingFormat:@"/%@"
,subPath];
//计算文件的大小
long long fileSize = [[filemanager
attributesOfItemAtPath:filePath
error:nil]fileSize
];
//加载到文件的大小
sumSize += fileSize;
}
float size_m = sumSize/(1000*1000
);
return [NSString
stringWithFormat:@"%.2fM"
,size_m];
}