Is this possible? My research suggests a walk function [os.walk()] or using the glob module?
Here is the code I have been using. Feel free to give any feedback on it as I am still a rookie with Python:
import arcpy, os
path = r"I:/ARC/DATA/MXDs/Weekly Report"
for fileName in os.listdir(path):
fullPath = os.path.join(path, fileName)
if os.path.isfile(fullPath):
basename, extension = os.path.splitext(fullPath)
if extension == ".mxd":
mxd = arcpy.mapping.MapDocument(fullPath)
print "MXD: " + fullPath
for df in arcpy.mapping.ListDataFrames(mxd):
for lyr in arcpy.mapping.ListLayers(mxd,"",df):
findthis = 'Positive Trees'
findthat = 'Infested Trees'
if findthis in
lyr.name or findthat in
lyr.name:
lyr.replaceDataSource(r'I:/ARC/Data/InfestedTrees/Infested_trees.gdb','FILEGDB_WORKSPACE','Trees')
print(
lyr.name + " - Layer Resourced to Infested Trees")
else:
pass
arcpy.RefreshTOC()
arcpy.RefreshActiveView()
mxd.save()
print "--Script complete--"