2

I have a project where I have many MXDs in one folder, and would like to export each one to JPGs in another folder. I've been stumped with a particular error message I'm running in to:

Runtime error

Traceback (most recent call last):

File "string", line 5, in module

WindowsError: [Error 123] The filename, directory name, or volume label syntax is incorrect: 'T:\Projects\t TIP\FY2018\New folder/.'

This is the code I'm using:

 import arcpy, os
 inputPath = 'T:\Projects\411 TIP\FY2018\FY2018 TIP Database.gdb'
 outputPath = 'T:\Projects\411 TIP\TIP Database\Project_Maps\2019'
 #Loop through each MXD file for filename in os.listdir(inputPath):    
 for filename in os.listdir(inputPath): 
    fullpath = os.path.join(inputPath, filename)     
    if os.path.isfile(fullpath):         
        if filename.lower().endswith(".mxd"):              
 #Reference MXD and export             
            mxd = arcpy.mapping.MapDocument(fullpath)             
 arcpy.mapping.ExportToJPEG(mxd, outputPath + "\\" + filename + ".jpg")

I apologize if this is a simple fix, I am new to using python.

4

for path variables use this r"this\is\your\path" the r stands for 'raw' it tells python this is a path string.

  • This suggestion cleared the error, however it only produced one .jpg in the target folder called "timestamp.jpg." Any idea why this is or how to correct it? – Owen Stuckey Jun 6 '17 at 19:31
  • Yah your export jpg command is outside of your loop – NULL.Dude Jun 6 '17 at 19:44
1

I've used this script when I want to loop through a folder that contains MXD files that are to be converted to PNG with a resolution of 600 pixels. Change the PNG to JPEG as well as the folderpath

 import arcpy, os

 folderPath = r"C:\Users\User\Downloads\demographic_siteselection"  
 for filename in os.listdir(folderPath):  
 fullpath = os.path.join(folderPath, filename)  
 if os.path.isfile(fullpath):  
    basename, extension = os.path.splitext(fullpath)  
    if extension.lower() == ".mxd":  
        mxd = arcpy.mapping.MapDocument(fullpath)  
        arcpy.mapping.ExportToPNG(mxd, basename + '.png', resolution = 600)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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