generate functionFri, 02 Dec 2022

Delete files that contain the word "TdarrCacheFile" in the filename on D:\.

import os def delete_files(path, searchTerm): for filename in os.listdir(path): file_path = os.path.join(path, filename) try: if searchTerm in filename: os.remove(file_path) except Exception as e: print(e) delete_files('D:\', 'TdarrCacheFile')

Questions about programming?Chat with your personal AI assistant