Computing the sum page count of all my .docx, .doc, .ppt, .pptx, and .pdf files within a certain directory; but am a little confused at how to count PowerPoint slides.
Here's what I've tried:
from glob import glob
from PyPDF2 import PdfFileReader
import win32com.client
def pdf_page_count(filename):
curr = open(filename, "rb")
page_count = PdfFileReader(curr).getNumPages()
curr.close()
return page_count
def presentation_slide_count(filename):
Application = win32com.client.Dispatch("PowerPoint.Application")
Presentation = Application.Presentations.Open(filename)
slide_count = len(Presentation.Slides)
Presentation.Close()
return slide_count
if __name__=='__main__':
powerpoints = glob('*/*/*.pptx') + glob('*/*/*.ppt')
documents = glob('*/*/*.docx') + glob('*/*/*.doc')
pdf = glob('*/*/*.pdf')
total_pdf_pages = sum([pdf_page_count(pdf) for pdf in pdf])
total_docx_pages = 0
total_powerpoint_slides = sum([presentation_slide_count(presentation)
for presentation in powerpoints])
print total_pdf_pages
print total_powerpoint_slides
Additionally I have tried using python-pptx however I received lxml errors (so tried to build my own lxml; which errored out on iconv dependency trouble). Also since that only supports pptx, I would need to find an alternative method for ppt. PowerPoint 2013 x64 is installed, and I am using Python 2.7.4 x64.
Okay, figured out the answer.
It doesn't seem to like relative paths.
Adding this line to that function solves the problem:
from os import getcwd
filename = getcwd() + '//' + filename
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With