python - 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-3.x - 从两个独立的音频数据流生成 2 通道波形文件
- python - 如何在python中使用列表索引号访问字典值?
- android - 如何将 Android APK 上传到 Fabric Beta
- asp.net-mvc - Vue + Asp.net 渲染问题
- sql-server - 删除多个数据库是否会删除已经存在的 SQL Server 代理作业?
- sql - 查询将两条记录合并为一条
- optimization - Pyomo:如何为每个 (i,j) 对编写约束
- css - Ruby on Rails 6 how to reference images from asset pipeline for css
- botframework - AAD 身份验证 Directline & Teams,禁用安全代码
- python - 使用枕头识别数独网格中的数字