1

I am super brand new to coding with python. For my work, we have ESRI maps (.MXDs) that need to be batch exported. The problem is that each map is in it's own folder within the main folder. I found a code to batch export my maps, if they are within the same directory (though it keeps giving an Invalid Syntax error). I also found a code that should look through all the subdirectories, but I do not know how to combine it with the first code.

Exporting my maps code (arcpy is how ArcMap uses python from what I gather):

import arcpy, os

arcpy.env.workspace = ws = r”C:\Users\Me\Desktop\Burn_Zones” #This is where I am getting that invalid syntax error!

mxd_list = arcpy.ListFiles("*.mxd")

for mxd in mxd_list:

        current_mxd = arcpy.mapping.MapDocument(os.path.join(ws, mxd))
    pdf_name = mxd[:-4] + ".pdf"
    arcpy.mapping.ExportToPDF(current_mxd, pdf_name)
del mxd_list

So that's the first issue. The code to look into all of the subdirectories is:

for root, dirs, files in os.walk(path):
for name in files:
    if name.endswith((".html", ".htm")):

I don't think I would need the second for loop as the first code should be grabbing all of the .mxds for me. So would I only need the first for loop and chunk that above the mxd_list = arpy.ListFiles(".mxd") line of code?

Oh, and for that error line. I have tried the path name with C:\ and with Burn_Zones\ and all the combinations of those. That didn't work and that's the only thing I could figure.

Thank y'all so much for any help!

1 Answers1

1

You're using the wrong quotes around your path. Is this your error?

arcpy.env.workspace = ws = r”C:\Users\162708\Desktop\Burn_Zones”
                            ^
SyntaxError: invalid character in identifier

Replace those "quotes" with actual double quotes.

r”C:\Users\162708\Desktop\Burn_Zones”  # wrong
r"C:\Users\162708\Desktop\Burn_Zones"  # correct
Jean-François Fabre
  • 137,073
  • 23
  • 153
  • 219
joebeeson
  • 4,159
  • 1
  • 22
  • 29
  • Do you mean like tick tick? ' ' (without the space) Or double quotes, like when reading what a someone said? " I tried both ways, but I am still getting the invalid syntax error. – Sarah_E_Johnson Dec 07 '16 at 21:48
  • 1
    It may be difficult to see, but ” is not " -- Python doesn't like ” as it is not a double quote but instead some sort of fancy quotes, commonly seen in Microsoft Word. – joebeeson Dec 07 '16 at 21:50
  • Oh! You are so brilliantly wonderful! I copy and pasted the baste code again and that worked! Thank you very much! – Sarah_E_Johnson Dec 07 '16 at 21:55
  • @Sarah_E_Johnson Glad that worked for you! Be sure to mark the question as solved. – joebeeson Dec 07 '16 at 21:55