AnsweredAssumed Answered

Change path for every mxd in a folder

Question asked by jbenson on Jun 18, 2013
Latest reply on Apr 13, 2016 by crombezk
Our office uses roaming profiles and redirected folders.  This means the location of each file in an mxd has the domain name in its path (\\xxxx.xxxx.xxx\...).  We just changed our domain from \\xxxx.xxxx.xxx\... to \\x2x2x2x2.x2x2x2x2x2\... where ... is the rest of the path that has not changed.  I tried to use python code to change the path of every mxd in the directory without success. I???ve had some help  as I am not a python programmer.  The first set of code gives an error message, Runtime Error! Program C:\PYTHON26\ARCGIS10.1\pythonw.exe abnormal program termination.  The second code completes, but does not change the path.  It does update the Date modified.  The print file statements were in for debugging.  What do I need to change to have the paths changed?  Surely someone has had to do this before.  FYI, I am using 10.1.  Thanks!

First code:
import arcpy, os, sys  # Folder location of maps that need updating. Setup for script tool. Can be changed to hardcoded path. folderpath = arcpy.GetParameterAsText(0)  arcpy.env.workspace = r"\\x2x2x2x2.x2x2x2x2x2\???-ocd\Users\my.name\My Documents" for file in arcpy.ListFiles("*.mxd"):     print file     mxd = arcpy.mapping.MapDocument(os.path.join(folderpath,file))     mxd.findAndReplaceWorkspacePaths(r"\\xxxx.xxxx.xxx", r"\\x2x2x2x2.x2x2x2x2x2")     mxd.save()     del mxd sys.exit()


Second code:
import arcpy, os, sys  # Folder location of maps that need updating. Setup for script tool. Can be changed to hardcoded path. folderpath = arcpy.GetParameterAsText(0)  arcpy.env.workspace = "\\\\nmfs.local\\akc-ocd\\Users\\jan.benson\\My Documents\\" for file in arcpy.ListFiles("*.mxd"):     print file     mxd = arcpy.mapping.MapDocument(os.path.join(folderpath,file))     print file     oldpath = "\\\\xxxx.xxxx.xxx\\???-ocd\\Users\\my.name\\My Documents\\"     newpath = "\\\\x2x2x2x2.x2x2x2x2x2\\???-ocd\\Users\\my.name\\My Documents\\"     mxd.findAndReplaceWorkspacePaths(oldpath, newpath)     print file     mxd.save()     del mxd

Outcomes