NSString *cachesPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];
NSFileManager *mgr = [NSFileManager defaultManager];
//计算caches目录大小
long long totalSize = 0;
NSArray *subpaths = [mgr subpathsAtPath:cachesPath];
for (NSString *subpath in subpaths) {
NSString *fullpath = [cachesPath stringByAppendingPathComponent:subpath];
BOOL dir = NO;
[mgr fileExistsAtPath:fullpath isDirectory:&dir];
if (dir == NO) { //文件
totalSize += [[mgr attributesOfItemAtPath:fullpath error:nil][NSFileSize] longLongValue];
}
}
NSLog(@"Libray/Caches目录的文件大小:%lld",totalSize);计算沙盒中Libray/Caches目录里所有文件的大小
最新推荐文章于 2016-05-09 16:19:50 发布
本文介绍了一种使用Objective-C代码来计算iOS应用中Library/Caches目录下所有文件总大小的方法。通过遍历指定路径下的所有子文件并累加每个文件的大小实现此功能。
1913

被折叠的 条评论
为什么被折叠?



