I am getting a directory name is invalid 'T:/TEST/TEST/11132020/IMGCD/00005202/131R.tif' I escaped the fp variable with forward slashes, so i am not understanding whats going on.
error
NotADirectoryError: [WinError 267] The directory name is invalid: 'T:/TEST/TEST/11132020/IMGCD/00005202/131R.tif'
code
def getCOAFilePaths(batchno, pdkey):
filename_l = []
for date in pdkey:
date = date
for batch in batchno:
filepath = 'T:/TEST/TEST/%s/IMGCD/%s' % (date, batch)
# abspth = os.path.abspath(filepath)
for fn in os.listdir(filepath):
# imgfp = filepath+"\\"+fn
filename_l.append(filepath+"/"+fn)
logging.info(filepath+"/"+fn)
return filename_l
def makePdf(filepath_l, SaveToDir):
for fp in filepath_l:
fp=fp
print(fp)
os.chdir(fp)
try:
for j in os.listdir(os.getcwd()):
os.chdir(fp)
fname, fext= os.path.splitext(j)
newfilename = fname + ".pdf"
im = Image.open(fname + fext)
os.chdir(SaveToDir)
im.save(newfilename, "PDF", resolution=100.0)
print(f"{newfilename} created succesfully!")
logging.info(f"{newfilename} created succesfully!")
except Image.UnidentifiedImageError:
print(f"{fname+fext} found. Skipping UnidentifiedImageError error because this library cannot open a .db file "
f"and convert it to pdf.")