How do I loop a folder of mxds

12416
43
05-10-2016 08:23 AM
DevinUnderwood2
Occasional Contributor

I want to loop many mxds within a folder to retrieve layer,connection,etc. information using python.

I just need the syntax for looping through the mxds.

0 Kudos
43 Replies
MichaelVolz
Esteemed Contributor

Search through geonet threads for Walk function in python.  You can also search outside geonet for python and walk.

DevinUnderwood2
Occasional Contributor

Looks like I need the arcpy.da.Walk and not the os.walk which doesn't return database related features.

Still working on it though.

0 Kudos
DanPatterson_Retired
MVP Esteemed Contributor

If you are interested in the innards of the mxd, many recommend ... https://www.arcgis.com/home/item.html?id=f0ae73e90c1a4992a1059e7d370966d4 X-ray

DevinUnderwood2
Occasional Contributor

Thank you for the advice. I have been using X-ray, but it doesn't quite fit my purpose. I need the mxd info written to a excel sheet to be used as a ArcGIS table.

Also, the most import need is to loop which X-ray is used on the currently opened mxd.

0 Kudos
MichaelVolz
Esteemed Contributor

What kind of database related features are you looking for?

0 Kudos
DevinUnderwood2
Occasional Contributor

I have the following since I am not sure whether os.walk limitation apples to me since I want to get feature classes information within mxds.

import arcpy, os

workspace = ' xxxxxx '

for root, dirs, files in os.walk(workspace):

        for f in files:
            if f.endswith(".mxd"):
                mxd = root + '\\' + f
                print f

I get a list of mxds which is the first successful step but I need the feature classes.

DevinUnderwood2
Occasional Contributor

FeatureClasess with info of their respective dataset.

0 Kudos
MichaelVolz
Esteemed Contributor

You'll need to get the DataFrames in your mxd

arcpy.mapping.ListDataFrames("name of mxd")

then you'll need to get the layers in each data frame

arcpy.mapping.ListLayers("name of mxd, "", "name of data frame")

DevinUnderwood2
Occasional Contributor

Can I input the workspace for listdataframes & listlayers since I want info on 19 mxds, not just one  ?

0 Kudos