Apr-04-2020, 01:13 PM
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)
