Sep-13-2020, 02:31 PM
Code then question:
2. Windows question, not really Python, so no biggie if I can't get help. Anyone know the most efficient way to delete thumbnail cache? The .db files are often in use by Explorer.exe and closing it doesn't always do the trick. I'm experimenting with the folder setting to disable thumnails, but so far I can't reliably figure out how to disable the lock Explorer has on the files.
import tkinter as T from tkinter import ttk from tkinter import messagebox import os import subprocess # Don't want to install a 3rd party module, so will collect system paths here: AppData = 'C:\\Users\\MaLonn\\AppData\\' class MainGUI(T.Tk): def __init__(self): T.Tk.__init__(self) self.main_frame = ttk.Frame(self, relief='ridge', borderwidth=2) self.main_frame.grid() self.protocol('WM_DELETE_WINDOW', self.close_window) self.main_labels() self.main_buttons() def close_window(self): self.destroy() def main_labels(self): lbl1 = ttk.Label(self.main_frame, text='Delete Thumbnail Files') lbl1.grid() def main_buttons(self): btn1 = ttk.Button(self.main_frame, text='Scan', command=self.delete_thumbs) btn1.grid() def main_messages(self, which): if which == 1: return messagebox.askyesno(title='Access Denied', message='Would ' 'you like to terminate the explorer process?') def scan_directory(self, path, recurs=0): with os.scandir(path) as it: for entry in it: if entry.is_dir(): if recurs: yield from self.scan_directory(entry.path, 1) elif entry.is_file(): yield entry.name def delete_thumbs(self): path = AppData + 'Local\\Microsoft\\Windows\\Explorer\\' tried = 0 for s in self.scan_directory(path): if s.startswith('thumb'): try: os.remove(path + s) except OSError: if tried == 0: if self.main_messages(1): kill = subprocess.run('Taskkill /IM Explorer.exe /F') tried = 1 else: continue if kill.returncode == 0: subprocess.run('C:\\Windows\\Explorer.exe') main_gui = MainGUI() main_gui.mainloop()1. The script launches a simple GUI, press the button and it is supposed to delete the thumbnail cache files in W10. Trouble I'm having is that if it needs to close explorer, upon launching it again another GUI window opens. Why?
2. Windows question, not really Python, so no biggie if I can't get help. Anyone know the most efficient way to delete thumbnail cache? The .db files are often in use by Explorer.exe and closing it doesn't always do the trick. I'm experimenting with the folder setting to disable thumnails, but so far I can't reliably figure out how to disable the lock Explorer has on the files.