I need a program which counts the pages of all the pdf files in a directory.
i found this scrpit which is supposet to do exactly that, but when i try to run it it just doesnt work for me it outputs nothing. i dont really know what to change in the code so that it will work for me when i replace the vPath with the diecetory of the file it just give me an error, please help im new to this and trying to get the hang of it. Thanks in advance
"""
This module contains a function to count
the total pages for all PDF files in one directory.
"""
#from time import clock as __c
from glob import glob as __g
from re import search as __s
cdef dict __count( char *vPath ):
#
cdef list vPDFfiles = __g( vPath + "\\" + '*.pdf' )
cdef int vPages = 0
cdef dict vMsg = {}
#
for vPDFfile in vPDFfiles:
vFileOpen = open( vPDFfile, 'rb', 1 )
for vLine in vFileOpen.readlines():
if "/Count " in vLine:
vPages = int( __s("/Count \d*", vLine).group()[7:] )
vMsg[vPDFfile] = vPages
vFileOpen.close()
#
return vMsg
#
def count( vPath ):
"""
Takes one argument: the path where you want to search the files.
Returns a dictionary with the file name and number of pages for each file.
"""
#cdef double ti = __c()
cdef dict v = __count( vPath )
#cdef double tf = __c()
print tf-ti
return v