Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need some help on my program. I have the parameters set to ask user to pick an mxd and the folder where those data driven PDFs are located. I started with Search Cursor to create a list from the Sheet_ID field of an mxd. To get total number of pages of that mxd. Now I need to write in for the program, to compare the list created from the Sheet numbers to the number of PDFs created and tell me if there is a difference in the total count. For Example: If there are 1 out of 11 sheets for the mxd, then there should be 11 PDFs created and so on. MY code is below:

#Purpose: Compares SheeID field to the toal PDFs created from Data Driven Pages Program
Import arcpy, os, string, sys

#Make parameters for people to choose mxd and folder of PDFs to compare
mxdList = string.split(arcpy.GetParameterAsText(0), ";")
dir = arcpy.GetParameterAsText(1)

#Use Search Cursor to go through Attribuite Table to get Sheet number info
rows = arcpy.SearchCursor(mxdList, "Sheet_ID")

#Use list from Sheet_ID field to match the number of PDFs created to get difference 
share|improve this question
i = 0
for x in os.listdir(dir):
    if x.endswith(".pdf"):
        i = i + 1

I think this should work.

.endswith is case sensitive, so you may want to populate a variable with the possible extensions like

extensions = '.pdf', '.PDF'

then the if statement becomes

if x.endswith(extensions)
share|improve this answer
Is my code for the Search Cursor correct? mxdList to grab the list the user created and Sheet_Id to name the field to make the list of total sheets. – Michelle Couden Mar 1 '13 at 21:11
Oh, sorry. You don't need a search cursor for that, you can just iterate through your mxdList Array. For each element in that array you'll want to work some magic from arcpy.mapping to count the pages for each data driven page.… – HeyOverThere Mar 1 '13 at 21:52
My code gives me an "Exception raised while running script" it stops right after import arcpy, os, string, sys. – Michelle Couden Mar 1 '13 at 21:53
You could also do x.lower().endswith(".pdf"). – blah238 Mar 5 '13 at 2:46

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.