/** 文件夹总大小 */
NSUInteger size = 0;
NSString * cachePath = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES).lastObject;
NSString * dirPath = [cachePath stringByAppendingPathComponent:@"文件夹名"];
NSFileManager * manager = [NSFileManager defaultManager];
/** 获取下一层文件夹路径,仅一层,不常用 */
// NSArray * arr1 =[manager contentsOfDirectoryAtPath:dirPath error:nil];
/** 获取所有子文件夹路径 */
NSArray * arr2 = [manager subpathsAtPath:dirPath];
for (NSString * subPath in arr2) {
/** 先拼出全路径 */
NSString * path = [dirPath stringByAppendingPathComponent:subPath];
/** 得到单个文件夹字典属性,里面存放有包含size等各种信息*/
NSDictionary * attrs =[manager attributesOfItemAtPath:path error:nil];
/** 累加大小 */
size += attrs.fileSize;
}
注:在windows下,单位间的换算是1024,而在MAC下则是1000.