I have this one specific layer in a bunch of mxd files with a broken data source. I am working on a script to automate fixing the data source. I am having trouble getting it to loop through a folder and fix the layer on all mxd files in that same folder.
This is the script I have so far:
#Import modules import arcpy from arcpy import env #Put file path for the folder containing mxds, where I have my sample file path env.workspace = r"G:\Geomatics\Map Requests\2017-07-24_TrailClosures" #Looping through all mxd documents, list layers and replace those layers MRGTrails layer with proper data source for file in arcpy.ListFiles("*.mxd"): mxd = arcpy.mapping.MapDocument(file) df = arcpy.mapping.ListDataFrames("*.mxd", "Layers") for lyr in arcpy.mapping.ListLayers(mxd, "*", df): if lyr.name == "Trails": lyr.replaceDataSource(r'G:\Geomatics\Data\Regional\MRG.gdb', "FILEGDB_WORKSPACE", "Trails_Sentiers", validate=False) mxd.save()