Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
os.remove is not working
#1
I tried to split a pdf file (e.g. called xyz.pdf) which is roughly 20 pages and I succeeded too. After I did the splitting, I try to delete the original file which is "xyz.pdf" by using os.remove(path). But the file is not getting removed and at the same time, it is getting deleted when I do it from separate .py file. Below is the code:

import os, datetime

date = datetime.datetime.now().strftime('%d%b')
root_path = "E:\\Downloads\\01 Newspapers\\Telugu PDF"


folders = [
#            'Andhrabhoomi',
            'Andhrajyothy',
            'Andhraprabha',
            'Prajasakti',
            'Sakshi'
            ]

for folder in folders :
    pdf_path = os.path.join (root_path, folder)
    file01 = date + " " + folder + " Pg.pdf"
    file02 = date + " " + folder + " Vwd City Pg.pdf"
        
    os.remove(pdf_path+'\\'+ file01)
    os.remove(pdf_path+'\\'+ file02)
    
    file03 = date + " " + folder + " Guntur City Pg.pdf"
    src_fi = pdf_path + "\\Guntur\\" + file03
    dst_fi = pdf_path + "\\Guntur\\" + file03[:-18] + " _Guntur.pdf"
    
    os.rename (src_fi, dst_fi)
Reply
#2
You write the file is not deleted. Does the program show an error message?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  remove elements method not working spalisetty06 4 4,289 Aug-13-2020, 01:17 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020