/**
-
計算單個文件大小
*/
+(long long)fileSizeAtPath:(NSString *)filePath{NSFileManager *manager = [NSFileManager defaultManager];
if ([manager fileExistsAtPath :filePath]){
return [[manager attributesOfItemAtPath :filePath error : nil ] fileSize];
}
return 0 ;
}
作者:iOS_凱
鏈接:http://www.reibang.com/p/5ebe4f21c486
來源:簡書
著作權歸作者所有螃成。商業(yè)轉載請聯(lián)系作者獲得授權,非商業(yè)轉載請注明出處查坪。
/**
-
清理緩存
*/
+(void)cleanCache:(cleanCacheBlock)block
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
//文件路徑
NSString *directoryPath=[NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject];NSArray *subpaths = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:directoryPath error:nil]; for (NSString *subPath in subpaths) { NSString *filePath = [directoryPath stringByAppendingPathComponent:subPath]; [[NSFileManager defaultManager] removeItemAtPath:filePath error:nil]; } //返回主線程 dispatch_async(dispatch_get_main_queue(), ^{ block(); });
});
}