generate functionTue, 29 Nov 2022

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

import os import time def delete_older(path, base, days): now = time.time() cutoff = now - (days * 86400) for dirName, subdirList, fileList in os.walk(path): for f in fileList: fp = os.path.join(dirName, f) if os.stat(fp).st_mtime < cutoff: if os.path.isfile(fp): os.unlink(fp) else: shutil.rmtree(fp, ignore_errors=True) delete_older("E:\usenet\tv\\", 14) delete_older("E:\usenet\movies\\", 14)

Questions about programming?Chat with your personal AI assistant