Feb-03-2019, 10:20 AM
(This post was last modified: Feb-03-2019, 10:20 AM by taffylim69.)
I heard that python can make life easier, I wanted to remove duplicates in folderA by comparing folderB with folderA, so I decided to download python and try coding with python. My code seems correct, however, my files are failing to delete, what's wrong with it?
I tried unlink but doesn't work.
I want my files deleted, basically folderA contains some files in folderB, and I'm trying to delete it.
I tried unlink but doesn't work.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
import os with open (r "C:\pathto\output.txt" , "w" ) as a: for path, subdirs, files in os.walk(r 'C:\pathto\directoryb' ): for filename in files: #f = os.path.join(path, filename) #a.write(str(f) + os.linesep) a.write( str (filename) + '\n' ) textFile = open (r 'C:\output.txt' , 'r' ) line = textFile.readline() while line: target = str (line) todelete = 'C:\directorya' + target if (os.path.exists(todelete)): os.remove(todelete) else : print ( "failed" ) line = textFile.readline() textFile.close() |