generate functionTue, 29 Nov 2022

Delete files and folders older than 14 days in "E:\usenet\movies\".

import os, time target_dir = "E:\\usenet\\movies" now = time.time() for f in os.listdir(target_dir): f = os.path.join(target_dir, f) if os.stat(f).st_mtime < now - 14 * 86400: if os.path.isfile(f): os.remove(f) else: shutil.rmtree(f)

Questions about programming?Chat with your personal AI assistant