import os
import send2trash as s2t
target = 'c:\\Python38-64\\OLD-BACKUP\\'
file = open('removed-files.txt', 'w')
for x in os.listdir(target):
if x.endswith('.dll'):
s2t.send2trash(target + x)
file.write(target + x + '\n')
file.close()
This script uses the send2trash module to send files with the .dll extension in the c:\Python38-64\OLD-BACKUP\ directory to the trash. The file paths of the deleted files are also written to a removed-files.txt file in write mode.
Here's a breakdown of the script:
import osandimport send2trash as s2timport the necessary modules for the script.target = 'c:\\Python38-64\\OLD-BACKUP\\'sets the target directory where the script will look for files with the.dllextension.file = open('removed-files.txt', 'w')opens a new file calledremoved-files.txtin write mode.for x in os.listdir(target):loops through the files in thetargetdirectory.if x.endswith('.dll'):checks if the current file has the.dllextension.s2t.send2trash(target + x)sends the file to the trash.file.write(target + x + '\n')writes the file path of the deleted file to theremoved-files.txtfile, followed by a newline character (\n).file.close()closes theremoved-files.txtfile.