/** 獲得緩存大小 */ - (NSString *)getCachSize { //總大小 unsigned long long size = 0; //得到緩存文件夾路徑 NSString *dirpath = [self dirpath]; //文件管理者 self.fileManager = [NSFileManager defaultManager]; //得到文件夾的大小 //得到該路徑下的全部文件名字 NSArray *subpaths = [self.fileManager subpathsAtPath:dirpath]; //累計全部文件大小 for (NSString *subpath in subpaths) { //全路徑 NSString *fulSubpath = [dirpath stringByAppendingPathComponent:subpath]; //累加文件大小 fileSize字典屬性,表示字典大小 size += [self.fileManager attributesOfItemAtPath:fulSubpath error:nil].fileSize; } NSString *sizeStr; if (size > 1024 * 1024) { size /= 1024 * 1024; sizeStr = [NSString stringWithFormat:@"%lluMB",size]; }else if (size > 1024){ size /= 1024; sizeStr = [NSString stringWithFormat:@"%lluKB",size]; }else{ sizeStr = [NSString stringWithFormat:@"%lluB",size]; } return sizeStr; } /** 清除緩存 */ - (void)deleteCach { UIAlertView *alert = [[UIAlertView alloc] init]; alert.title = @"提示"; [alert addButtonWithTitle:@"肯定"]; NSString *msg; NSString *dirpath = [self dirpath]; if ([self.fileManager fileExistsAtPath:dirpath]) { if ([self.fileManager removeItemAtPath:dirpath error:nil]) { msg = @"清楚緩存成功"; }else msg = @"清楚緩存失敗"; }else msg = @"緩存不存在"; alert.message = msg; [alert show]; [self.tableView reloadData]; }