import os
import send2trash as s2t
target = 'c:\\Python38-64\\OLD-BACKUP\\'
for x in os.listdir(target):
if x.endswith('.pyd'):
s2t.send2trash(target + x)
This script uses the os
module to list all files in a directory, and send2trash
module to delete only files with the ".pyd" extension.
Here's how the code works:
target
variable is set to the directory path where the script will delete files with the ".pyd" extension.- The
os.listdir(target)
function is used to get a list of all files in the directory. - A
for
loop is used to iterate through each file in the list. - An
if
statement checks if the file has the ".pyd" extension. If so, thesend2trash()
function is used to delete the file to the Recycle Bin. - The file is deleted using
send2trash()
instead ofos.remove()
to send the file to the Recycle Bin instead of permanently deleting it.
This script is useful for deleting specific files from a directory without permanently deleting them.
No comments:
Post a Comment