I need to remove the first page of multiple pdf files in a directory. I am an elementary level python user and I have cobbled together the following code from bits & pieces of other code that I have. However, I cannot get it to work. Does anything jump out at anyone?
from PyPDF2 import PdfFileWriter, PdfFileReader
import os, sys
directory_name = 'emma'
for filename in directory_name:
print 'name: %s' % filename
output_file = PdfFileWriter()
input_handle = open(filename+'.pdf', 'rb')
input_file = PdfFileReader(input_handle)
num_pages = input_file.getNumPages()
print "document has %s pages \n" % num_pages
for i in xrange(1, num_pages):
output_file.addPage(input_file.getPage(i))
print 'added page %s \n' % i
output_stream = file(filename+'-stripped.pdf','wb')
output_file.write(output_stream)
output_stream.close()
input_handle.close()
Error message:
input_handle = open(filename+'.pdf', 'rb')
IOError: [Errno 2] No such file or directory: 'a.pdf'
open()call. It's not even connected toPyPDF2. Please do a reasonable amount of preliminary diagnostics and/or googling yourself before asking questions on the Net and making others waste their time on them.