I am getting the error while deleting the files in folder.
Below is my code.
Part-1 of coding
pdf = FPDF()
sdir = "D:/IMAGES/"
w, h = 0, 0
for i in range(1, 25):
fname = (sdir + str(i) + ".jpeg")
if os.path.exists(fname):
if i == 1:
cover = Image.open(fname)
w, h = cover.size
pdf = FPDF(unit="pt", format=[w, h])
image = fname
pdf.add_page()
pdf.image(image, 0, 0, w, h)
else:
pdf.output(
r"D:\DOCUMENTS\Google Drive\NewsPapers\Lokmat\Lokmat Mumbai Main "+str(d+A+Y)+".pdf", "F")
pdf.close
Part-2 of coding
import os
dir_name = "D:/IMAGES/"
test = os.listdir(dir_name)
for item in test:
if item.endswith(".jpeg"):
os.remove(os.path.join(dir_name, item))
print("Done")
print("--- %s seconds ---" % (time.time() - start_time))
Error I am getting is as below:
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'D:/IMAGES/1.jpeg'