删除文件:
/*
*获取全部的用户的缓存区
*/
NSFileManager*mgr=[NSFileManagerdefaultManager];
NSString*caches=[NSSearchPathForDirectoriesInDomains(NSCachesDirectory,NSUserDomainMask,YES)lastObject];
NSLog(@"caches
%@",caches);
//删除文件擦caches
[mgrremoveItemAtPath:cacheserror:nil];
NSString+Extension.m
-(NSInteger)fileSize{
NSFileManager*mgr=[NSFileManagerdefaultManager];
BOOLdir=NO;
BOOLexist=[mgrfileExistsAtPath:selfisDirectory:&dir];
if(exist==NO) {//文件不存在
return0;
}
if(dir) {//传递路径文件是一个文件夹遍历获取每个文件的大小并拼接起来
NSArray*subPaths=[mgrsubpathsAtPath:self];
//NSLog(@"%@",subPaths);
NSIntegertotalBytesSize=0;
for(NSString*subPathinsubPaths) {//遍历文件路径
NSString*fullPath=[selfstringByAppendingPathComponent:subPath];
BOOLdir2=NO;
[mgrfileExistsAtPath:fullPathisDirectory:&dir2];
//NSLog(@"dir2:%hhd",dir2);
if(dir2==NO) {//是文件拼接大小
totalBytesSize+=[[mgrattributesOfItemAtPath:fullPatherror:nil][NSFileSize]integerValue];
}
}
returntotalBytesSize;
}else{//是一个文件
return[[mgrattributesOfItemAtPath:selferror:nil][NSFileSize]integerValue];
}
}
ImageCache图片
//图片字节大小
intbyteSize = [SDImageCachesharedImageCache].getSize;
//
M大小
doublesize = byteSize / 1000.0 / 1000.0;
self.navigationItem.title= [NSStringstringWithFormat:@"缓存大小(%.1fM)", size];
//清除缓存
[[SDImageCachesharedImageCache]clearDisk];