import arcpy, os path = r"N:\Temporary_Work\Oliver Morris\EDCOLLINS_ISOPACH" 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: " + fileName brknList = arcpy.mapping.ListBrokenDataSources(mxd) for brknItem in brknList: lyr.replaceDataSource (r" N:\Temporary_Work\mapping_2011.mdb", "ACCESS_WORKSPACE", SEA_110617) print "\t" + brknItem.name del mxd
>>> import arcpy, os ... path = r"N:\Temporary_Work\Oliver Morris\EDCOLLINS_ISOPACH" ... 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: " + fileName ... brknList = arcpy.mapping.ListBrokenDataSources(mxd) ... for brknItem in brknList: ... lyr.replaceDataSource (r"N:\Temporary_Work\Oliver Morris\EDCOLLINS_ISOPACH\Isopach_mapping_2011.mdb","ACCESS_WORKSPACE","SEA_ODM_ISOPACH_110617") ... print "\t" + brknItem.name ... del mxd ... MXD: ISOPACH_EDIT1_EDCOLLINS.mxd Runtime error <type 'exceptions.NameError'>: name 'lyr' is not defined >>>
import arcpy, os path = r"N:\Temporary_Work\Oliver Morris\EDCOLLINS_ISOPACH" 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: " + fileName brknList = arcpy.mapping.ListBrokenDataSources(mxd) for brknItem in brknList: for lyr in brknItem: lyr.replaceDataSource (r" N:\Temporary_Work\Oliver Morris\EDCOLLINS_ISOPACH\Isopach_mapping_2011.mdb","ACCESS_WORKSPACE","SEA_ODM_ISOPACH_110617") print "\t" + brknItem.name del mxd
import arcpy, os path = r"N:\Temporary_Work\Oliver Morris\EDCOLLINS_ISOPACH" 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: " + fileName brknList = arcpy.mapping.ListBrokenDataSources(mxd) for brknItem in brknList: if brknItem.supports("DATASOURCE"): lyr.replaceDataSource(r" N:\Temporary_Work\Oliver Morris\EDCOLLINS_ISOPACH\Isopach_mapping_2011.mdb","ACCESS_WORKSPACE","SEA_ODM_ISOPACH_110617") print "\t" + brknItem.name del mxd