0

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.")
Ben21
  • 93
  • 9
  • 1
    That appears to be the pathname of one of your image files, *not* a directory. I can't tell for sure since you didn't post the full traceback, but I would assume that the error occurred during one of your `chdir()` calls, which is meaningless to apply to a file. – jasonharper Nov 20 '20 at 17:22
  • 1
    Please have a look at pathlib. It is a more robust way to do this. – dawg Nov 20 '20 at 17:29

0 Answers0