import os import shutil import stat import time import argparse def get_yes_no(prompt, default = False): while True: i = input(prompt+f" [{'Y' if default else 'y'}/{'N' if not default else 'n'}] ") if not i: return default if i.lower() == "y": return True elif i.lower() == "n": return False # logfile = time.strftime("%Y%m%d-%H%M%S") parser = argparse.ArgumentParser() parser.add_argument("-y", "--yes", help="Say yes to everything automatically", action="store_true") args = parser.parse_args() if os.name not in ('nt', "dos"): print("Ez a program csak Windows alatt képes futni.") exit(1) ROOT = r"C:\Windows\Temp" print() print("Mappa betöltése...") ntotal = len(os.listdir(ROOT)) nfolders = 0 nfiles = 0 nreparse = 0 blacklist = [] next_status = 0 for file in os.listdir(ROOT): if os.path.isdir(os.path.join(ROOT, file)): nfolders += 1 else: nfiles += 1 if next_status <= time.time(): next_status = time.time() + 0.2 n = nfolders+nfiles+nreparse print(f"\r{(nfiles+nfolders+nreparse)/ntotal*100:.02f}% ({nfiles}:{nfolders}/)", end="") print(f"\r{(nfiles+nfolders+nreparse)/ntotal*100:.02f}% ({nfiles}:{nfolders})", end="") print() print() print("'Temp' mappa tartalma:") print(f" * Fájlok: {nfiles}") print(f" * Mappák: {nfolders}") print() if args.yes or get_yes_no("Ki azeretné törölni ezeket a fájlokat? (Általában biztonságos)"): ndel = 0 print(nfiles+nfolders, "elem törlése...") next_status = time.time() for file in os.listdir(ROOT): ndel += 1 try: if os.path.join(ROOT, file).startswith(ROOT): if os.path.isdir(os.path.join(ROOT, file)): shutil.rmtree(os.path.join(ROOT, file)) else: os.remove(os.path.join(ROOT, file)) else: print("[*** ERROR ***] SOMETHING WENT VERY WRONG! DELETION PATH DOES NOT MATCH TEMP ROOT.") except Exception as e: print(f"[** ERROR **] {file} nem törölhető: {e}") if next_status <= time.time(): next_status = time.time() + 0.2 print(f"{ndel/ntotal*100:.02f}% ({ndel}/{ntotal})") print(f"{ndel / ntotal * 100:.02f}% ({ndel}/{ntotal})") print()