AnsweredAssumed Answered

Loop through folder of MXD and change server name

Question asked by brianmcleer on Jun 20, 2019
Latest reply on Jun 20, 2019 by brianmcleer

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


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)
print 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: " + + " 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

del mxd

# delete the original MXD
print "\tDeleted: " + fullPath