首页 > 解决方案 > NotADrectoryError 路径错误 - 转义反斜杠

问题描述

我得到一个目录名称无效 'T:/TEST/TEST/11132020/IMGCD/00005202/131R.tif' 我用正斜杠转义了 fp 变量,所以我不明白发生了什么。

错误

NotADirectoryError: [WinError 267] The directory name is invalid: 'T:/TEST/TEST/11132020/IMGCD/00005202/131R.tif'

代码

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.")

标签: python

解决方案


推荐阅读