I am trying to traverse through every file in my downloads folder, deleting any duplicate files. But every time I run the script, I get the error: "FileNotFoundError: [WinError 2] The system cannot find the file specified: ... " Here is my code:
import os
path = 'C:/Users/walte/Downloads'
for root,dirNames,fileNames in os.walk( path ):
for file in fileNames:
name, ext = os.path.splitext( file )
if name.endswith( ")" ):
os.remove( file )
If I use print(file) instead of using os.remove, all duplicate files are listed. Here is the terminal output:
CS 499 Self-evaluation and reflection (1)
CS 499 Self-evaluation and reflection (2)
Detection (1)
Detection (2)
Detection (3)
JavaSetup8u241 (1)
That is causing confusing on why this isn't working. Thanks for the help!
question from:
https://stackoverflow.com/questions/65931301/is-there-a-way-to-delete-all-duplicate-files-in-the-downloads-folder-using-pytho 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…