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
  Random access binary files with mmap - drastically slows with big files danart 1 119 Jun-17-2019, 10:45 AM
Last Post: danart
  Code works in IDLE, appears to work in CMD, but won't produce files in CMD/Windows ChrisPy33 3 294 Jun-12-2019, 05:56 AM
Last Post: ChrisPy33
  Help with finding correct topic in Python learning yahya01 1 227 Jun-06-2019, 05:01 PM
Last Post: buran
  Delete Lines that Contain Words - Loop through files in a folder - Write to new files dj99 3 250 May-18-2019, 06:34 AM
Last Post: heiner55
  Return in correct json format UtiliseIT 3 259 May-13-2019, 11:24 AM
Last Post: snippsat
  How to continue in loop until correct input received sunnyarora 10 355 May-04-2019, 02:37 PM
Last Post: Yoriz
  Scanning files to rename other files in the same folder. msd1391 6 292 Mar-11-2019, 07:19 PM
Last Post: msd1391
  What is the correct type hint when you want to accept Iterable but not Dictionary LadySvetlana 4 210 Mar-05-2019, 07:33 PM
Last Post: LadySvetlana
  numpynot associted with correct python version ErnestTBass 17 757 Jan-16-2019, 02:47 PM
Last Post: ErnestTBass
  Correct number wrong position func. albry 5 392 Jan-11-2019, 04:01 PM
Last Post: Larz60+

Forum Jump:

Users browsing this thread: 1 Guest(s)