0

I have a folder containing multiple .mxd files. I wish to list all of the layer names and data sources for each .mxd from the folder. I am using the following code which lists the above for one .mxd but how do I loop the code to work through all .mxds in the folder?

import arcpy mxd = arcpy.mapping.MapDocument("D:\MXDs\Air_quality.mxd") for lyr in arcpy.mapping.ListLayers(mxd): if lyr.supports("DATASOURCE"): print " MIS Name: " + lyr.name + " Data Source: " + lyr.dataSource 

1 Answer 1

2
>>> import arcpy,os >>> dp=r'D:\MXDs' >>> arcpy.env.workspace=r'D:\MXDs' >>> mxds=arcpy.ListFiles("*.mxd") >>> for mxd in mxds: ... fp=os.path.join(dp,str(mxd)) ... md=arcpy.mapping.MapDocument(fp) ... layerlist=arcpy.mapping.ListLayers(md) ... for layer in layerlist: ... if layer.supports("DATASOURCE"): ... print "layer name :"+layer.name+"source :"+layer.dataSource 

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.