刪除文件:
/*
*獲取全部的用戶的緩存區(qū)
*/
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圖片
//圖片字節(jié)大小
intbyteSize = [SDImageCachesharedImageCache].getSize;
//
M大小
doublesize = byteSize / 1000.0 / 1000.0;
self.navigationItem.title= [NSStringstringWithFormat:@"緩存大小(%.1fM)", size];
//清除緩存
[[SDImageCachesharedImageCache]clearDisk];