generate functionMon, 28 Nov 2022

Delete file and folders older than 7 days in "E:\usenet\tv\".

import os import time now = time.time() for root, dirs, files in os.walk('E:\usenet\tv'): for f in files: if os.stat(os.path.join(root, f)).st_mtime < now - 7 * 86400: if os.path.isfile(os.path.join(root, f)): os.remove(os.path.join(root, f)) else: shutil.rmtree(os.path.join(root, f))

Questions about programming?Chat with your personal AI assistant