我正在使用的代码接收一个 .pdf 文件,并输出一个 .txt 文件。我的问题是,如何创建一个循环(可能是 for 循环),该循环在以“.pdf”结尾的文件夹中的所有文件上一遍又一遍地运行代码?此外,如何在每次循环运行时更改输出,以便每次都可以编写一个与输入文件同名的新文件(即 1_pet.pdf > 1_pet.txt、2_pet.pdf > 2_pet.pdf)。 txt等)
这是到目前为止的代码:
path="2_pet.pdf"
content = getPDFContent(path)
encoded = content.encode("utf-8")
text_file = open("Output.txt", "w")
text_file.write(encoded)
text_file.close()
Run Code Online (Sandbox Code Playgroud)