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 os
andimport send2trash as s2t
import 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.dll
extension.file = open('removed-files.txt', 'w')
opens a new file calledremoved-files.txt
in write mode.for x in os.listdir(target):
loops through the files in thetarget
directory.if x.endswith('.dll'):
checks if the current file has the.dll
extension.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.txt
file, followed by a newline character (\n
).file.close()
closes theremoved-files.txt
file.
No comments:
Post a Comment