generate functionMon, 28 Nov 2022

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

import os, time def delete_files(folder_path): now = time.time() for f in os.listdir(folder_path): file_path = os.path.join(folder_path, f) if os.stat(file_path).st_mtime < now - 7 * 86400: if os.path.isfile(file_path): os.remove(file_path) elif os.path.isdir(file_path): os.rmdir(file_path) delete_files(r'E:\usenet\tv') delete_files(r'E:\usenet\movies')

Questions about programming?Chat with your personal AI assistant