Allowing for possible unknown file names to be processed in a python script
Question: I am using a script that overlays an input pdf onto another that is
essentially a letterhead. However, I am not sure how to allow for the process
to be automated to allow for many files to be processed one at a time, without
previously knowing what the file will be named. I am using python 2.7.

    
    
    from pyPdf import PdfFileWriter, PdfFileReader
    
    
    output = PdfFileWriter()
    input1 = PdfFileReader(file("example.pdf", "rb"))
    
    # add page 1 from input1 to output document, unchanged
    output.addPage(input1.getPage(0))
    
    # add page 2 from input1, but first add a watermark from another pdf:
    page2 = input1.getPage(0)
    watermark = PdfFileReader(file("template.pdf", "rb"))
    page2.mergePage(watermark.getPage(0))
    
    output.addPage(page2)
    
    
    # finally, write "output" to document-output.pdf
    outputStream = file("example.pdf", "wb")
    output.write(outputStream)
    outputStream.close()
    


Answer: Import os and use os.listdir to look in a particular directory for the files:

<https://docs.python.org/2/library/os.html#os.listdir>

