0

I am trying to merge multiple files using PyPDf2 within a folder in my office's shared drive. However, my program never finishes running because I believe that it does not have permission to access the folder. Is there a way to allow access to it?

from PyPDF2 import PdfFileMerger
import os

path = "H:\\Accounting\\ME\\Attachments\\Pdf"
pdf_files = ["\\file1.pdf", "\\file2.pdf"]
merger = PdfFileMerger()
    for files in pdf_files:
        merger.append(path + files)
    if not os.path.exists(path + "\\newMerged.pdf"):
        merger.write(path + "\\newMerged.pdf")
merger.close()
print("done")
  • This is a problem with file permissions, not Python. – Sean Pianka Jul 30 '18 at 14:27
  • so should I use try/catch to figure out the error? Is it because it's not getting read correctly? – jarhead4123 Jul 30 '18 at 14:50
  • Your indentation is a little off, in that your `if` is outside of your `for` loop, was that intentional? And do you have permission to access `file1.pdf` and `file2.pdf`? Are you receiving any errors? – Sean Pianka Jul 30 '18 at 14:52
  • Yes, it was intentional but it should work either way I think and when I run the code with the path set as my desktop it runs fine. I have also tried to rotate the page from the same path and it also works – jarhead4123 Jul 30 '18 at 15:19
  • I had a similar issue writing an appended merged pdf to shared network drive. I thought it may be a permissions issue, but it was not. This fixed the issue for me: with open(output_filename, "wb") as f: merger.write(f) – KNAPPYFLASH Nov 01 '22 at 04:32

0 Answers0