、、、
//获取文件夹大小
NSFileManager *mgr = [NSFileManager defaultManager];
NSString *caches = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)lastObject];
//文件夹的属性
//NSDictionary *attrs = [mgr attributesOfItemAtPath:caches error:nil];
//获得文件夹的属性,文件夹没有大小遍历所有文件加起来活儿文件的大小
//获取caches里面的所有内容
//NSArray *contents = [mgr contentsOfDirectoryAtPath:caches error:nil];
NSArray *subPaths = [mgr subpathsAtPath:caches];
NSInteger totalByteSize = 0;
for (NSString *subPath in subPaths)
{
NSString *fullPath = [caches stringByAppendingPathComponent:subPath];
//判断是文件还是文件夹
BOOL dir = NO;
[mgr fileExistsAtPath:fullPath isDirectory:&dir];
if (dir == NO)
{
//文件
NSDictionary *attrs = [mgr attributesOfItemAtPath:fullPath error:nil];
NSInteger byteSize = [attrs[NSFileSize] integerValue];
totalByteSize += byteSize;
}
}
NSLog(@"%ld",totalByteSize);
、、、
清缓存
、、、
//删除该文件夹
[mgr removeItemAtPath:caches error:nil];
、、、