Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 The code seems correct but my files aren't getting deleted
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.
    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)):
     line = textFile.readline()
I want my files deleted, basically folderA contains some files in folderB, and I'm trying to delete it.
you cannot delete the file while it is still open.

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  How to check if video has been deleted or removed in youtube using python Prince_Bhatia 14 3,014 Feb-21-2020, 04:33 AM
Last Post: jehoshua
  Getting the error like function not defined .. suggest correct code raghava 1 168 Feb-04-2020, 11:20 PM
Last Post: micseydel
  A code to generate new files in my HDD yokharian 2 975 Feb-09-2018, 07:28 PM
Last Post: yokharian
  My if and while loop statements aren't working RedSkeleton007 7 1,557 Oct-21-2017, 07:06 AM
Last Post: buran

Forum Jump:

Users browsing this thread: 1 Guest(s)