We are changing our production server to have a prefix of 'HV'. I have a folder of MXDs I would like to update to the new server, but I am missing something from my code below. I got my start from https://gist.github.com/davehorsey/d8892b150e61d2e03617.
import arcpy, os
path = r"C:\layouts"
for fileName in os.listdir (path):
basename, extension = os.path.splitext(fileName)
# select MXD files that do NOT begin with "Copy_of_" - this
# prevents the script from updating files that have already been updated
if (extension == ".mxd") and (fileName[:8] != "Copy_of_"):
fullPath = os.path.join(path, fileName)
mxd = arcpy.mapping.MapDocument(fullPath)
# update data sources
mxd.findAndReplaceWorkspacePaths("Database Connections\\Server Database NT Auth.sde", "Database Connections\\HV_Server Database NT Auth.sde")
print "\tUpdated: SDE data sources"
# check for broken links
brknList = arcpy.mapping.ListBrokenDataSources(mxd)
for brknItem in brknList:
print "\tCheck: " + brknItem.name + " data source broken"
if not brknList:
print "\tCheck: no broken data sources"
# save a copy of the MXD
saveACopy_filename = "Copy_of_" + fileName
saveACopy_fullpath = os.path.join(path, saveACopy_filename)
print "\tSaved: " + saveACopy_filename
# delete the original MXD
print "\tDeleted: " + fullPath