简单的python清理程序!

import os
from getpass import getuser
from time import sleep
from psutil import disk_partitions
from shutil import rmtree
from ctypes import windll
import threadingdel_extension = {'.tmp': '临时文件','._mp': '临时文件_mp','.log': '日志文件','.gid': '临时帮助文件','.chk': '磁盘检查文件','.old': '临时备份文件','.xlk': 'Excel备份文件','.bak': '临时备份文件bak','Temps': 'Temp文件','Watch dog': 'Watch dog','upgrade files': '系统更新/补丁'
}del_userprofile = ['cookies', 'recent', 'Temporary Internet Files', 'Temp']
del_windir = ['prefetch', 'temp']
SYS_DRIVE = os.environ['systemdrive'] + '\\'
USER_PROFILE = os.environ['userprofile']
WIN_DIR = os.environ['windir']
tf = False
disks = disk_partitions()def del_dir_or_file(root):try:if os.path.isfile(root):os.remove(root)print('file ' + root + " removed", end='. \n')elif os.path.isdir(root):rmtree(root)print('dir ' + root + " removed", end='. \n')except WindowsError:print("failure " + root + " can't remove", end='. \n')def f1():global tfwhile True:if tf:breakfor s in ['/', '-', '\\']:if tf:breakprint(s, end='')sleep(0.25)print('', end='\r')def formatSize(b):try:kb = b // 1024except:print("传入字节格式不对")return "Error"if kb > 1024:M = kb // 1024if M > 1024:G = M // 1024return "%dGB" % Gelse:return "%dMB" % Melse:return "%dKB" % kbclass DiskClean(object):def __init__(self):self.del_info = {}self.del_file_paths = []self.total_size = 0self.places = [r'''C:\WINDOWS\Performance\WinSAT\winsat.log''',r'''C:\WINDOWS\PFRO.log''',r'''C:\WINDOWS\WindowsUpdate.log''',r'''C:\Users\Administrator\AppData\Local\Microsoft\CLR_v4.0_32\UsageLogs\Avira.SystemSpeedup.Core.Common.Starter.exe.log''',r'''C:\Users\Peter\AppData\Local\Microsoft\CLR_v4.0\UsageLogs\Overwolf.exe.log''',r'''C:\Users\Peter\AppData\Local\Microsoft\CLR_v4.0\UsageLogs\OverwolfBrowser.exe.log''',r'''C:\Users\Peter\AppData\Local\Microsoft\CLR_v4.0\UsageLogs\OverwolfUpdater.exe.log''',r'''C:\Users\Peter\AppData\Local\Microsoft\CLR_v4.0\UsageLogs\OWinstaller.exe.log''',r'''C:\WINDOWS\Logs\CBS''',r'''C:\WINDOWS\Logs\DISM''',r'''C:\WINDOWS\Logs\DPX''',r'''C:\WINDOWS\Logs\MeasuredBoot''',r'''C:\WINDOWS\Logs\MoSetup''',r'''C:\WINDOWS\Logs\NetSetup''',r'''C:\WINDOWS\Logs\SIH''',r'''C:\WINDOWS\Logs\SystemRestore''',r'''C:\WINDOWS\Logs\waasmedic''',r'''C:\WINDOWS\Logs\waasmediccapsule''',r'''C:\WINDOWS\Logs\WindowsUpdate''',r'''C:\WINDOWS\Logs\WinREAgent''',r'''C:\ProgramData\USOShared\Logs\System''',r'''C:\ProgramData\USOShared\Logs\User''',r'''C:\WINDOWS\system32\LogFiles\setupcln\diagerr.xml''',r'''C:\WINDOWS\system32\LogFiles\setupcln\diagwrn.xml''',r'''C:\WINDOWS\system32\LogFiles\setupcln\setupact.log''',r'''C:\WINDOWS\system32\LogFiles\setupcln\setuperr.log''',r'''C:\WINDOWS\system32\LogFiles\WMI\BioEnrollment.etl''',r'''C:\WINDOWS\system32\LogFiles\WMI\FaceTel.etl''',r'''C:\WINDOWS\system32\LogFiles\WMI\FaceUnlock.etl''',r'''C:\WINDOWS\system32\LogFiles\WMI\LwtNetLog.etl''',r'''C:\WINDOWS\system32\LogFiles\WMI\Microsoft-Windows-Rdp-Graphics-RdpIdd-Trace.etl''',r'''C:\WINDOWS\system32\LogFiles\WMI\NetCore.etl''',r'''C:\WINDOWS\system32\LogFiles\WMI\NtfsLog.etl''',r'''C:\WINDOWS\system32\LogFiles\WMI\RadioMgr.etl''',r'''C:\WINDOWS\system32\LogFiles\WMI\ReFSLog.etl''',r'''C:\WINDOWS\system32\LogFiles\WMI\RtBackup''',r'''C:\WINDOWS\system32\LogFiles\WMI\Wifi.etl''',r'''C:\WINDOWS\debug\WIA''',r'''C:\Users\Peter\AppData\Roaming\Tencent\Logs''',r'''C:\Users\Peter\AppData\Roaming\BaiduYunGuanjia\logs''',r'''C:\users\Peter\appdata\local\CrashDumps''']for i, j in del_extension.items():self.del_info[i] = dict(name=j, count=0)def scanf(self):# for i in range(50):for roots, dirs, files in os.walk(USER_PROFILE):for files_item in files:file_extension = os.path.splitext(files_item)[1]if file_extension in self.del_info:file_full_path = os.path.join(roots, files_item)self.del_file_paths.append(file_full_path)self.del_info[file_extension]['count'] += 1self.total_size += os.path.getsize(file_full_path)if os.path.isdir(r'C:\Windows.old'):self.del_file_paths.append(r'C:\Windows.old')if os.path.isdir(rf'C:\Users\{getuser()}\AppData\Local\Temp'):for roots, dirs, files in os.walk(rf'C:\Users\{getuser()}\AppData\Local\Temp'):for files_item in files:file_extension = os.path.splitext(files_item)[1]file_full_path = os.path.join(roots, files_item)self.del_file_paths.append(file_full_path)self.del_info['Temps']['count'] += 1for dir_item in dirs:file_full_path = os.path.join(roots, dir_item)self.del_file_paths.append(file_full_path)self.del_info['Temps']['count'] += 1if os.path.isdir(r'C:\WINDOWS\LiveKernelReports\WATCHDOG'):for roots, dirs, files in os.walk(r'C:\WINDOWS\LiveKernelReports\WATCHDOG'):for files_item in files:file_extension = os.path.splitext(files_item)[1]file_full_path = os.path.join(roots, files_item)self.del_file_paths.append(file_full_path)self.del_info['Watch dog']['count'] += 1for dir_item in dirs:file_full_path = os.path.join(roots, dir_item)self.del_file_paths.append(file_full_path)self.del_info['Watch dog']['count'] += 1if os.path.isdir(r'C:\Windows\SoftwareDistribution\Download'):for roots, dirs, files in os.walk(r'C:\Windows\SoftwareDistribution\Download'):for files_item in files:file_extension = os.path.splitext(files_item)[1]file_full_path = os.path.join(roots, files_item)self.del_file_paths.append(file_full_path)self.del_info['upgrade files']['count'] += 1for dir_item in dirs:file_full_path = os.path.join(roots, dir_item)self.del_file_paths.append(file_full_path)self.del_info['upgrade files']['count'] += 1if os.path.isdir(rf'C:\Documents and Settings\{getuser()}\Local Settings\temp'):for roots, dirs, files in os.walk(rf'C:\Documents and Settings\{getuser()}\Local Settings\temp'):for files_item in files:file_extension = os.path.splitext(files_item)[1]file_full_path = os.path.join(roots, files_item)self.del_file_paths.append(file_full_path)self.del_info['Temps']['count'] += 1for dir_item in dirs:file_full_path = os.path.join(roots, dir_item)self.del_file_paths.append(file_full_path)self.del_info['Temps']['count'] += 1if os.path.isdir(r'C:\Windows\Temp'):for roots, dirs, files in os.walk(r'C:\Windows\Temp'):for files_item in files:file_extension = os.path.splitext(files_item)[1]file_full_path = os.path.join(roots, files_item)self.del_file_paths.append(file_full_path)self.del_info['Temps']['count'] += 1for dir_item in dirs:file_full_path = os.path.join(roots, dir_item)self.del_file_paths.append(file_full_path)self.del_info['Temps']['count'] += 1for pop in self.places:self.del_file_paths.append(pop)def show(self):global rrerre = formatSize(self.total_size)for i in self.del_info:print(self.del_info[i]["name"], "共计", self.del_info[i]["count"], "个")print(f'共计{formatSize(self.total_size)}')return rredef delete_files(self):for i in self.del_file_paths:del_dir_or_file(i)@staticmethoddef clean_Recycle_bin():windll.shell32.SHEmptyRecycleBinW()print('empty')if __name__ == "__main__":print("初始化清理垃圾程序")cleaner = DiskClean()print("开始扫描垃圾文件请耐心等待\n")thread1 = threading.Thread(target=f1)thread1.start()cleaner.scanf()tf = Trueprint("\r扫描成功,结果如下")rre = cleaner.show()cleaner.delete_files()ft = input('是否清理回收站?(y/n):')if ft == 'y':DiskClean.clean_Recycle_bin()ft = input('确认退出?(y/n):')if ft == 'y':exit()

抱歉,只能下载v2了。

下载地址:http://t.csdn.cn/9Svoa

python 清理程序相关推荐

  1. python编辑器和终端_从python curses程序运行终端文本编辑器

    我想在python curses程序中使用外部终端文本编辑器和寻呼机.我使用子进程库.在大多数情况下,它工作得很好,除了当我退出文本编辑器时(与nemo和vi相同),我不能再次使光标不可见.另外,在调 ...

  2. 解释python脚本程序的name变量及其作用_一些概念总结

    is 与 == 的区别 Python中万物皆对象,每个对象都包含3个属性:id,type,value.1.id就是对象地址,可以通过内置函数id()查看对象引用的地址.2.type就是对象类型,可以通 ...

  3. 用Python清理收藏夹里已失效的网站,快测试一下你的收藏夹吧

    最近打开好多以前收藏的网站,发现好多都已经失效了,好多以前想看还没来得及看的内容,也找不见了... 失效的书签们 我们日常浏览网站的时候,时不时会遇到些新奇的东西,于是我们就默默的点了个收藏或者加书签 ...

  4. python购物车程序2019_Python实现购物车程序

    本文实例为大家分享了程序:Python购物车程序,具体内容如下 需求: 启动程序后,让用户输入工资,然后打印商品列表 允许用户根据商品编号购买商品 用户选择商品后,检测余额是否够,够就直接扣款,不够就 ...

  5. python 获取程序运行时间

    python 获取程序运行时间 import time # 时间测试 start =time.time() # 运行程序 for i in range(100000000):pass end =tim ...

  6. 《Python 3程序开发指南(第2版•修订版)》——1.2 Python的关键要素

    本节书摘来自异步社区<Python 3程序开发指南(第2版•修订版)>一书中的第1章,第1.2节,作者[英]Mark Summerfield,王弘博,孙传庆 译,更多章节内容可以访问云栖社 ...

  7. spark指定python版本_如何将正常的Python应用程序正确转换为PySpark版本

    我是PySpark的初学者,最近我尝试向我的Spark集群提交一个简单的python应用程序(批量调整大小图片).我可以成功地通过pycharm运行该应用程序,并且当我将应用程序提交给spark时,图 ...

  8. python语言包含的错误,Python语言程序中包含的错误,一般分为三种,以下____________不是其中的一种...

    Python语言程序中包含的错误,一般分为三种,以下____________不是其中的一种 答:编译错误 人体体温能自动调控在37度,其原因是( ). 答:人体内产生的热能是分批放出的 人体内有完善的 ...

  9. C++/Php/Python/Shell 程序按行读取文件或者控制台方法总结。

    C++/Php/Python/Shell 程序按行读取文件或者控制台方法总结. 一.总结 C++/Php/Python/Shell 程序按行读取文件或者控制台(php读取标准输入:$fp = fope ...

最新文章

  1. 原创 | 入门“大数据”,你需要通读这18本书
  2. 灵活运用ISA的链接转换功能:ISA2006系列之十三
  3. 彻底澄清:C#方法参数
  4. 年入近1亿,曾被20家VC拒绝,如今电商是他大客户,数据处处有黄金
  5. .Net Core下通过Proxy 模式 使用 WCF
  6. python远程调用摄像头_Python设置Socket代理及实现远程摄像头控制的例子
  7. zabbix 监控使用宏自动发现网卡并进行监控
  8. 微信打开页面底部显示“原页面已由QQ浏览器云转码”解决办法
  9. stl之map容器的原理及应用
  10. angular6、7 兼容ie9、10、11
  11. java面向接口编程详解
  12. 《神探tcpdump第八招》-linux命令五分钟系列之四十二
  13. 对象转json字符串(带转义字符)
  14. imagej得到灰度图数据_用ImageJ处理空间成像数据
  15. 【asm基础】使用vs创建asm库
  16. centos检测不到磁盘_CentOS下磁盘坏道的检测及修复
  17. java的StadIn函数_Java經典算法案例---Java深入
  18. mysql phpwind_php+mysql及phpwind和wordpress的安装配置
  19. 电脑开机黑屏错误代码U盘重装系统教学
  20. 惠州市有哪些学计算机的学校,惠州有哪些好学校?

热门文章

  1. 华为网络技术打卡2(云DC)
  2. 科技应该跨越年龄鸿沟
  3. 小程序源码:强大的多功能图片处理器微信小程序源码下载图片画框合成-多玩法安装简单
  4. 世界各国Google网址大全
  5. shields 徽标_基本徽标设计的简单指南
  6. objection使用
  7. 【互联网企业名称由来系列】一:阿里巴巴
  8. 编写程序,输出2000年到2100年的闰年
  9. 大神级人物,用C++带你们解答国际象棋中的N皇后问题
  10. html中的固定定位的用法