generate functionTue, 29 Nov 2022

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

def delete_old_files(path, age_in_days): now = time.time() for f in os.listdir(path): f = os.path.join(path, f) if os.stat(f).st_mtime < now - age_in_days * 86400: if os.path.isfile(f): os.remove(f) elif os.path.isdir(f): shutil.rmtree(f)

Questions about programming?Chat with your personal AI assistant