generate functionTue, 29 Nov 2022

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

import os import time #target = 'E:\usenet\tv\\' target = 'E:\usenet\movies\\' now = time.time() for root, dirs, files in os.walk(target): for f in files: path_file = os.path.join(root, f) if os.stat(path_file).st_mtime < now - 14 * 86400: if os.path.isfile(path_file): os.remove(path_file) for d in dirs: path_dir = os.path.join(root, d) if os.stat(path_dir).st_mtime < now - 14 * 86400: if os.path.isdir(path_dir): os.rmdir(path_dir)

Questions about programming?Chat with your personal AI assistant