Select to view content in your preferred language

Updated Description In All MXD's in a folder/subfolders

3173
4
Jump to solution
03-08-2011 05:01 AM
by Anonymous User
Not applicable
Original User: cdeaner66

New to Python here so please be patient.
I need to update the Map Document Properties Description field in hundreds of maps in one folder and multiple sub folders. 

I figured out how to add a description to the current map by using the following:

import arcpy
    mxd = arcpy.mapping.MapDocument ("CURRENT")
    mxd.desc = "Description Text Here"

How do I modify this to loop through all the MXD's in my folder/subfolders to update this field in each map?

Any insight/help would be appreciated!

Thanks,
Chris
0 Kudos
1 Solution

Accepted Solutions
JasonScheirer
Esri Alum
Let me know how this works for you:

import arcpy
import glob
import os

# Provide folder path to loop through (first level only)
folderPath = r"C:\TEMP\test"
for filename in glob.glob(os.path.join(folderPath, "*.mxd")):
    print "Editing", filename
    mxd = arcpy.mapping.MapDocument(filename)
    if not mxd.description:
        mxd.description = "Default description"
    mxd.save()
    del mxd

View solution in original post

0 Kudos
4 Replies
by Anonymous User
Not applicable
Original User: cdeaner66

I found another script to do something similar to what I was looking to do and modified it for my needs.
It works (kind of), the only problem is I have 3 mxd's in the folder and it is only updating the last one.

Any suggestions?

Here is the code:

import arcpy, os
# Provide folder path to loop through (first level only)
folderPath = r"C:\TEMP\test"
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)
  mxd.description  = "Python Test Description"
  mxd.save()
del mxd
0 Kudos
JasonScheirer
Esri Alum
Let me know how this works for you:

import arcpy
import glob
import os

# Provide folder path to loop through (first level only)
folderPath = r"C:\TEMP\test"
for filename in glob.glob(os.path.join(folderPath, "*.mxd")):
    print "Editing", filename
    mxd = arcpy.mapping.MapDocument(filename)
    if not mxd.description:
        mxd.description = "Default description"
    mxd.save()
    del mxd
0 Kudos
by Anonymous User
Not applicable
Original User: cdeaner66

Thanks for the help Jason, it worked great!
Python is new to me and I appreciate the assistance.

Chris
0 Kudos
San_Mateo_CountyGIS
Deactivated User
The script worked for me as long as the 'description' field was empty.
Is there a way to overwrite an existing description for all MXD's in a folder?

Thanks
0 Kudos