-(long long)fileSizeAtPath:(NSString *)path{
NSFileManager *fileManager=[NSFileManager defaultManager];
if([fileManager fileExistsAtPath:path]){
long long size=[fileManager attributesOfItemAtPath:path error:nil].fileSize;
return size;
}
return 0;
}
-(float)folderSizeAtPath:(NSString *)path{
NSFileManager *fileManager=[NSFileManager defaultManager];
NSString *cachePath=[NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject];
cachePath=[cachePath stringByAppendingPathComponent:path];
long long folderSize=0;
if ([fileManager fileExistsAtPath:cachePath])
{
NSArray *childerFiles=[fileManager subpathsAtPath:cachePath];
for (NSString *fileName in childerFiles)
{
NSString *fileAbsolutePath=[cachePath stringByAppendingPathComponent:fileName];
long long size=[self fileSizeAtPath:fileAbsolutePath];
folderSize += size;
NSLog(@"fileAbsolutePath=%@",fileAbsolutePath);
}
//SDWebImage框架自身计算缓存的实现
folderSize+=[[SDImageCache sharedImageCache] getSize];
return folderSize/1024.0/1024.0;
}
return 0;
}
//同样也是利用NSFileManager API进行文件操作,SDWebImage框架自己实现了清理缓存操作,我们可以直接调用。
-(void)clearCache:(NSString *)path{
NSString *cachePath=[NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject];
cachePath=[cachePath stringByAppendingPathComponent:path];
NSFileManager *fileManager=[NSFileManager defaultManager];
if ([fileManager fileExistsAtPath:cachePath]) {
NSArray *childerFiles=[fileManager subpathsAtPath:cachePath];
for (NSString *fileName in childerFiles) {
//如有需要,加入条件,过滤掉不想删除的文件
NSString *fileAbsolutePath=[cachePath stringByAppendingPathComponent:fileName];
NSLog(@"fileAbsolutePath=%@",fileAbsolutePath);
[fileManager removeItemAtPath:fileAbsolutePath error:nil];
}
}
[[SDImageCache sharedImageCache] cleanDisk];
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有