磁盘清理工具

删除文件夹下面的所有文件(只删除文件,不删除文件夹)

import osimport shutilimport statimport threadingimport timeimport tkinter as tkfrom tkinter import ttk, ENDfrom time import sleepfrom tkinter import messageboxfrom tkinter.filedialog import askdirectory# Temp-临时文件path_data1 = “C:\Windows\Temp”# Prefetch-访问记录path_data2 = “C:\Windows\Prefetch”# Download-系统更新时下载的补丁和一些安装包等path_data3 = “C:\Windows\SoftwareDistribution\Download”# LogFiles-系统日志及操作记录path_data4 = “C:\Windows\System32\LogFiles"path_data_diy = “”# python删除文件的方法 os.remove(path)path指的是文件的绝对路径,如:# os.remove(r"E:\code\practice\data\1.py”)#删除文件# os.rmdir(r"E:\code\practice\data\2")#删除文件夹(只能删除空文件夹)# shutil.rmtree(r"E:\code\practice\data\2")#删除文件夹# path_data = “E:\code\practice\data”#def thread_it(func, *args): “”“将函数打包进线程”"" # 创建 t = threading.Thread(target=func, args=args) # 守护 !!! t.setDaemon(True) # 启动 t.start() # 阻塞–卡死界面! # t.join()class GUI: def init(self): self.root = tk.Tk() self.root.title(“DDPl文件操作”) self.root.configure(bg=’#2c3038’) self.root.option_add(’*Font’, ‘楷体’) # self.root.geometry(“500x200+1100+150”) # 程序运行时在屏幕中间打开 sw = self.root.winfo_screenwidth() sh = self.root.winfo_screenheight() ww = 1055 wh = 550 x = (sw - ww) / 2 y = (sh - wh) / 2 self.root.geometry("%dx%d+%d+%d" % (ww, wh, x, y)) self.root.resizable(False, False) self.root.update() self.root.wm_attributes(’-topmost’, 1) self.interface() def interface(self): self.CheckVar1 = tk.IntVar() self.CheckVar2 = tk.IntVar() self.CheckVar3 = tk.IntVar() self.CheckVar4 = tk.IntVar() self.C1 = tk.Checkbutton(self.root, text=“Temp-临时文件”, variable=self.CheckVar1, onvalue=1, offvalue=0, fg=’#d9f5ff’, bg=’#2c3038’, selectcolor=’#2c3344’, activebackground=’#2c3038’, activeforeground=’#60b6fc’) self.C2 = tk.Checkbutton(self.root, text=“Prefetch-访问记录”, variable=self.CheckVar2, onvalue=1, offvalue=0, fg=’#d9f5ff’, bg=’#2c3038’, selectcolor=’#2c3344’, activebackground=’#2c3038’, activeforeground=’#60b6fc’) self.C3 = tk.Checkbutton(self.root, text=“Download-系统更新补丁”, variable=self.CheckVar3, onvalue=1, offvalue=0, fg=’#d9f5ff’, bg=’#2c3038’, selectcolor=’#2c3344’, activebackground=’#2c3038’, activeforeground=’#60b6fc’) self.C4 = tk.Checkbutton(self.root, text=“LogFiles-系统日志”, variable=self.CheckVar4, onvalue=1, offvalue=0, fg=’#d9f5ff’, bg=’#2c3038’, selectcolor=’#2c3344’, activebackground=’#2c3038’, activeforeground=’#60b6fc’) self.C1.select() self.C2.select() self.C3.select() self.C4.select() self.C1.grid(row=0, column=0, ipadx=10, ipady=10, padx=3, pady=10) self.C2.grid(row=0, column=1, ipadx=10, ipady=10, padx=3, pady=10) self.C3.grid(row=0, column=2, ipadx=10, ipady=10, padx=3, pady=10) self.C4.grid(row=0, column=3, ipadx=10, ipady=10, padx=3, pady=10) self.Button0 = tk.Button(self.root, text=“清理基本C盘垃圾”, command=lambda: thread_it(self.event_清理基本C盘垃圾), width=10, bg=’#4a8e53’, fg=’#d9f5ff’, activebackground=’#4d535f’, activeforeground=’#fdfdfd’) self.Button0.grid(row=0, column=4, ipadx=20, ipady=10, padx=5, pady=10) self.w1 = tk.Entry(self.root, textvariable=‘请输入目标路径’, bg=’#25272c’, fg=’#b2b2b2’) self.w1.grid(row=1, column=0, columnspan=4, ipadx=290, ipady=8, padx=5, pady=10) self.Button1 = tk.Button(self.root, text=“选择目标文件夹”, command=lambda: thread_it(self.event_选择目标文件夹), width=10, bg=’#4780ac’, fg=’#d9f5ff’, activebackground=’#4d535f’, activeforeground=’#fdfdfd’) self.Button1.grid(row=1, column=4, ipadx=20, ipady=10, padx=5, pady=10) self.Button2 = tk.Button(self.root, text=“清理目标文件夹”, command=lambda: thread_it(self.event_清理目标文件夹), width=10, bg=’#4a8e53’, fg=’#d9f5ff’, activebackground=’#4d535f’, activeforeground=’#fdfdfd’) self.Button2.grid(row=1, column=5, ipadx=20, ipady=10, padx=5, pady=10) self.Button3 = tk.Button(self.root, text=“清空输出信息”, command=lambda: thread_it(self.event_清空输出信息), width=10, bg=’#2c3038’, fg=’#d9f5ff’, activebackground=’#4d535f’, activeforeground=’#fdfdfd’) self.Button3.grid(row=0, column=5, ipadx=20, ipady=10, padx=5, pady=10)
self.text = tk.Text(self.root, bg=’#25272ct’, fg=’#777c8a’)
self.text.grid(row=2, column=0, columnspan=6, ipadx=195, padx=10, pady=10) # 新建滚动条 self.scroll = tk.Scrollbar() # 两个控件关联 self.scroll.config(command)

  • 17
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值