Created
March 1, 2018 16:10
-
-
Save mu88/94ff4b871e38db5378c27a28aaa58b30 to your computer and use it in GitHub Desktop.
ArcPy - Get Layer Data Sources of MXDs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import arcpy, codecs, csv, os | |
mxd_folder = "C:\\temp\\MXDs" | |
output = "C:\\temp\\dataSources.csv" | |
f = codecs.open(output, "w", encoding="utf-8") | |
f.write("MXD;Layer;Data Source\n") | |
for file in os.listdir(mxd_folder): | |
if file.endswith(".mxd"): | |
mxd = os.path.join(mxd_folder, file) | |
mxdFilename = os.path.splitext(file)[0] | |
mapDocument = arcpy.mapping.MapDocument(mxd) | |
for lyr in arcpy.mapping.ListLayers(mapDocument): | |
layerName = lyr.name | |
if lyr.supports("DATASOURCE"): | |
layerDataSource = lyr.dataSource | |
f.write(mxdFilename + "; " + layerName + "; " + layerDataSource + "\n") | |
else: | |
f.write(mxdFilename + "; " + layerName + "; <<COULD NOT READ DATA SOURCE>>\n") | |
f.close() | |
print "Completed" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment