generate functionTue, 29 Nov 2022

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

import os, datetime, time, shutil def delete_old(path, days_old): for f in os.listdir(path): f = os.path.join(path, f) if os.stat(f).st_mtime < time.time() - days_old * 86400: if os.path.isfile(f): os.remove(f) print ('Deleted', f) elif os.path.isdir(f): shutil.rmtree(f) print ('Deleted', f) delete_old('E:\usenet\tv\\', 14) delete_old('E:\usenet\movies\\', 14)

Questions about programming?Chat with your personal AI assistant