【发布时间】:2021-04-15 03:44:08
【问题描述】:
所以我正在使用 Python 进行 PDF 合并,因为我发现它对于像我这样的初学者来说是一个很好的项目。我从使用 PyPDF4 开始,在完成了所有艰苦的工作(不是那么难)之后,我运行了该程序,却被“FileNotFoundError: [Errno 2] No such file or directory:' 1.pdf'”。 第一个问题,它确实找到了指定目录中的文件名,并且确实存在于那里。它是如何找到它的名字但仍然说它不存在的?第二个问题,我该如何摆脱这个:
我使用 # 来保持代码干净,不要介意!
# <------Import Modules-------->
from PyPDF4 import PdfFileMerger
from os import listdir
# <-----------Misc------------->
filedirinput = input("Please enter a directory destination: ")
pdf = (".pdf")
# <-----Merge our Files------------------
manager = PdfFileMerger()# <------------| PdfFileMerger is now "manager" so that Karens can call it anytime XD
for files in listdir(filedirinput):# <--| For all the files in our Input Directory
if files.endswith(pdf):# <-------| Check if file ends with .pdf and move to next step
manager.append(files)# <--------| Merge all our files in the Directory using Manager (PdfFileMerger)
# <--------Output Time YE!!!--------->
outputname = input("Please enter your desired filename: ")
manager.write(outputname + pdf)
# <-----------Misc------------->
print(f"{outputname + pdf} was generated in {filedirinput}")
# NOTE This part is in development and you currently CANNOT mail somebody
# ALSO, I might turn all of this into a Tkinter GUI program :)
print("Do you want to email this to someone: Y/N")
yn = input("> ")
if yn == "N":
print("Thank You for Using PyDF Merger :)")
print("Made By NightMX!")
我遇到错误:https://imgur.com/a/sXGpq7R
祝你有美好的一天!,
【问题讨论】:
-
你应该在这里发布你的代码
-
您是否尝试过提供 PdfFileMerger 的绝对路径,而不是相对路径?
-
我只用那个
标签: python