I've got code to walk through an entire directory and sub-directories repair broken links in each mxd and save the mxd. It works for the mxd's in the top directory but fails when trying to enter any sub.
My code is as follows:
import arcpy, os
from arcpy import env
arcpy.env.overwriteOutput = True
ws = "C:\Users\mittcla\Desktop\New folder"
oldpath = r"C:\NewProjects"
oldbase = r"C:\Base Data"
newpath = r"C:\Users\mittcla\Documents\NewProjects"
newbase = r"C:\Users\mittcla\Documents\Base Data"
for root, dirs, files in os.walk(ws):
for f in files:
if f.endswith('.mxd'):
fullpath = os.path.join(ws,f)
mxd = arcpy.mapping.MapDocument(fullpath)
print "Replacing path for " + f +"..."
mxd.findAndReplaceWorkspacePaths(oldpath, newpath)
mxd.findAndReplaceWorkspacePaths(oldbase, newbase)
mxd.save()
del mxd
I get an error saying
Runtime error Traceback (most recent call last): File "", line 14, in File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\arcobjects\mixins.py", line 609, in init assert (os.path.isfile(mxd) or (mxd.lower() == "current")), gp.getIDMessage(89004, "Invalid MXD filename") AssertionError: Invalid MXD filename.
What is causing it to break when entering the new directory?
os.walk
.