[Object-c]获取文件的大小 清除缓存
2015-07-21 17:35
621 查看
app功能: 清除缓存
//获取缓存文件路径-(NSString *)getCachesPath{
// 获取Caches目录路径
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *cachesDir = [paths objectAtIndex:0];
NSString *filePath = [cachesDir stringByAppendingPathComponent:@"com.zxinsight.yiqiwan"];
return filePath;
}
///计算缓存文件的大小的M
- (long long) fileSizeAtPath:(NSString*) filePath{
NSFileManager* manager = [NSFileManager defaultManager];
if ([manager fileExistsAtPath:filePath]){
return [[manager attributesOfItemAtPath:filePath error:nil] fileSize];
}
return 0;
}
- (float ) folderSizeAtPath:(NSString*) folderPath{
NSFileManager* manager = [NSFileManager defaultManager];
if (![manager fileExistsAtPath:folderPath]) return 0;
NSEnumerator *childFilesEnumerator = [[manager subpathsAtPath:folderPath] objectEnumerator];//从前向后枚举器//////
NSString* fileName;
long long folderSize = 0;
while ((fileName = [childFilesEnumerator nextObject]) != nil){
NSString* fileAbsolutePath = [folderPath stringByAppendingPathComponent:fileName];
folderSize += [self fileSizeAtPath:fileAbsolutePath];
}
return folderSize/(1024.0*1024.0);
}
-(void)deleteFile {
NSFileManager* fileManager=[NSFileManager defaultManager];
//文件名
NSString *uniquePath=[self getCachesPath];
BOOL blHave=[[NSFileManager defaultManager] fileExistsAtPath:uniquePath];
if (!blHave) {
NSLog(@"no have");
return ;
}else {
NSLog(@" have");
BOOL blDele= [fileManager removeItemAtPath:uniquePath error:nil];
if (blDele) {
NSLog(@"dele success");
}else {
NSLog(@"dele fail");
}
}
}
相关文章推荐
- sqlserver 中一些常看的指标和清除缓存的方法
- 多种浏览器清除缓存的方法小结
- xmlhttp缓存清除的2种解决方法
- window.showModalDialog两次加载问题清除缓存方法
- UIWebView清除缓存和cookie
- php 文件夹删除、php清除缓存程序
- 屏蔽掉应用程序界面的"清除数据"功能
- SDWebImage手动清除缓存的方法
- Android清除数据、清除缓存、一键清理的区别
- 浏览器如何清除缓存
- android清除缓存为什么总是存在12k?
- iOS 清理某一个cookies 或者全部 cookies
- nginx清除缓存图片
- Varnish---原理及应用
- 工作记录--清除VD预留缓存
- iOS开发 ---- Xcode清除多余的证书provisioning profile,清除缓存
- php--------删除一个路径下的所有文件夹和文件
- [一句秒懂]ios 清除缓存
- webview清除缓存
- weblogic清除缓存