import os import time FOLDER = "/tmp" MAX_AGE_MINUTES = 60 def clean_old_files(folder=FOLDER, max_age=MAX_AGE_MINUTES): now = time.time() for f in os.listdir(folder): path = os.path.join(folder, f) if os.path.isfile(path): if now - os.path.getmtime(path) > max_age * 60: try: os.remove(path) print(f"[Cleanup] Deleted: {path}") except Exception as e: print(f"[Cleanup Error] {e}") if __name__ == "__main__": clean_old_files()