大家好
我有一批文件夹里的pdf都要合并,
但都合并在自己的文件夹里,
可是我用循环遍历结果合并 了好多次,请问问题在哪里,
下面是代码,谢谢- time1 = time.time()
- doc_files = []
- outfile = "combo2.pdf"
- time2 = time.time()
- # dirs = os.listdir(path)
- file_dir = r"I:\临时文件3.0"
-
-
-
- for root, dirs, filenames in walk(file_dir):
- for d in dirs:
- file_list = [f for f in os.listdir(os.path.join(root,d)) if f.endswith('.pdf')]
- file_list = [os.path.join(root,d, filename) for filename in file_list]
-
-
-
-
- file_merger = PdfFileMerger()
- for pdf in pdf_lst:
-
- file_merger.append(pdf) # 合并pdf文件
-
- file_merger.write(os.path.join(root, d, out))
复制代码
|