I am creating a script that walks through folders and scans for mxds. I use a set to get unique data sources and copy the data to a new folder keeping the same data format. I would then like to access the map document and repath all layers and tables to the copied data. I'm struggling to get the tables repathing code to work. In the below example, I have a fGDB table in the mxd and have copied the fGDB that it sits in to a new folder. I would thus like to repath to the table in the copied fGDB.
import arcpy, os
mxdrep = arcpy.mapping.MapDocument("CURRENT")
dfsrep = arcpy.mapping.ListDataFrames(mxdrep)
ignoreStringList = ["Vendor", "vendor", ".sde"]
dbFolder = os.path.join(projFolderPath, "Databases")
for dfrep in dfsrep:
tablesRep = arcpy.mapping.ListTableViews(mxdrep, "", dfrep)
for tableRep in tablesRep:
tablesRep = arcpy.mapping.ListTableViews(mxdrep, "", dfrep)
tabRepDataSrc = tableRep.dataSource
tableRepView = arcpy.mapping.TableView(tabRepDataSrc)
if not any(folders in str(tabRepDataSrc) for folders in ignoreStringList):
tabDirPath = tableRep.workspacePath
tabWsPath = os.path.dirname(tabDirPath)
tableRepView.findAndReplaceWorkspacePath(str(tabWsPath), dbFolder)