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!