#python3
import os,send2trash
import tkinter as tk
import tkinter.messagebox
from tkinter import filedialog
#弹出对话框,获取指定文件夹路径
def GetDir():
tkinter.messagebox.showinfo('提示' ,'请选择工作目录')
file_path = tkinter.filedialog.askdirectory()
return file_path
#遍历并删除指定大小的文件
def DeleteFile(floder):
folder=os.path.abspath(floder)
if not os.path.exists(folder):
print('no this file')
return
else:
for foldername,subfolders,filenames in os.walk(folder):
print('root is %s..\n'%filenames)
print('dirs is %s..\n'%subfolders)
print('files is %s..\n'%foldername)
for foldername,subfolders,filenames in os.walk(folder):
print('root is %s..\n'%filenames)
print('dirs is %s..\n'%subfolders)
print('files is %s..\n'%foldername)
for subfloder in subfolders:
for foldername in filenames:
if subfolders:
newPath=folder+'\\'+subfloder+'\\'+foldername
else:
newPath=folder+'\\'+foldername
print('get the filename: %s\n'%foldername)
print('the end=%s\n'%newPath)
Size=os.path.getsize(newPath)
if Size > 100*1024:
print('the file is so big ,size=%d'% Size)
send2trash.send2trash(newPath)
else:
print('the file is normal size=%d'%Size)
if __name__ == '__main__':
filepath=GetDir()
print('get the path is %s'%filepath)
DeleteFile(filepath)