I have a python script that I am using to create a list of all mxd files (with full pathing) in our Projects folder. The script then uses that to iterate through the list and do a findandreplaceworkspacepaths on each mxd per ESRI's how to. I am running into problems when I hit a corrupted mxd file. The have tried try/except and haven't gotten it to work. The ideal situation would be to write the corrupt filename to a file and move on so I can come back to them at the end. I'm very new with python scripting, any help would be greatly appreciated.
import arcpy, os, sys, traceback, time
oldpath = 'W:'
newpath = 'W:\\GIS'
def find(path,pattern):
matches = []
for r,d,f in os.walk(path):
for files in f:
if files.endswith(pattern):
fpath = os.path.join(r,files)
matches.append(fpath)
print (fpath)
return matches
print ("Go: ")
mxdlist = (find('C:\\gis','.mxd'))
print (mxdlist)
print ("Starting Path Conversion")
try:
for mxdold in mxdlist:
mxd = arcpy.mapping.MapDocument(mxdold)
mxd.findAndReplaceWorkspacePaths(oldpath, newpath)
time.sleep(6)
mxd.save()
time.sleep(6)
print (mxdold)
del mxd
except arcpy.ExecuteError:
arcpy.AddError(arcpy.GetMessages(2))
except:
arcpy.AddError("Non-tool error occurred")