<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Change path for every mxd in a folder in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/change-path-for-every-mxd-in-a-folder/m-p/583306#M45737</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Jan,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I believe the problem is with the arcpy.mapping.MapDocument function.&amp;nbsp; After performing some tests, it doesn't seem like you can use a UNC path with this function.&amp;nbsp; For example, if I run the following code the MXDs will not be updated:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy, os, sys&amp;nbsp; folderpath = r"\\server\temp\python"&amp;nbsp; arcpy.env.workspace = r"\\server\temp\python" for file in arcpy.ListFiles("*.mxd"): &amp;nbsp;&amp;nbsp;&amp;nbsp; mxd = arcpy.mapping.MapDocument(os.path.join(folderpath,file)) &amp;nbsp;&amp;nbsp;&amp;nbsp; oldpath = r"C:\Temp\Python\Test.gdb" &amp;nbsp;&amp;nbsp;&amp;nbsp; newpath = r"\\server\Temp\Python\Test.gdb" &amp;nbsp;&amp;nbsp;&amp;nbsp; mxd.findAndReplaceWorkspacePaths(oldpath, newpath) &amp;nbsp;&amp;nbsp;&amp;nbsp; mxd.save()&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; del mxd&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;However, if I replace the 'folderpath' variable with an absolute path, the code will update the MXDs successfully:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy, os, sys&amp;nbsp; folderpath = r"C:\temp\python"&amp;nbsp; arcpy.env.workspace = r"\\server\temp\python" for file in arcpy.ListFiles("*.mxd"): &amp;nbsp;&amp;nbsp;&amp;nbsp; mxd = arcpy.mapping.MapDocument(os.path.join(folderpath,file)) &amp;nbsp;&amp;nbsp;&amp;nbsp; oldpath = r"C:\Temp\Python\Test.gdb" &amp;nbsp;&amp;nbsp;&amp;nbsp; newpath = r"\\server\Temp\Python\Test.gdb" &amp;nbsp;&amp;nbsp;&amp;nbsp; mxd.findAndReplaceWorkspacePaths(oldpath, newpath) &amp;nbsp;&amp;nbsp;&amp;nbsp; mxd.save()&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; del mxd&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm not sure if this is by design, or if this is a bug.&amp;nbsp; May be worth logging an incident with tech support.&amp;nbsp; Are you able to use an absolute path rather than a UNC path for the folderpath variable?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 18 Jun 2013 18:18:52 GMT</pubDate>
    <dc:creator>JakeSkinner</dc:creator>
    <dc:date>2013-06-18T18:18:52Z</dc:date>
    <item>
      <title>Change path for every mxd in a folder</title>
      <link>https://community.esri.com/t5/python-questions/change-path-for-every-mxd-in-a-folder/m-p/583305#M45736</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Our office uses roaming profiles and redirected folders.&amp;nbsp; This means the location of each file in an mxd has the domain name in its path (\\xxxx.xxxx.xxx\...).&amp;nbsp; We just changed our domain from \\xxxx.xxxx.xxx\... to \\x2x2x2x2.x2x2x2x2x2\... where ... is the rest of the path that has not changed.&amp;nbsp; I tried to use python code to change the path of every mxd in the directory without success. I???ve had some help&amp;nbsp; as I am not a python programmer.&amp;nbsp; The first set of code gives an error message, Runtime Error! Program C:\PYTHON26\ARCGIS10.1\pythonw.exe abnormal program termination.&amp;nbsp; The second code completes, but does not change the path.&amp;nbsp; It does update the Date modified.&amp;nbsp; The print file statements were in for debugging.&amp;nbsp; What do I need to change to have the paths changed?&amp;nbsp; Surely someone has had to do this before.&amp;nbsp; FYI, I am using 10.1.&amp;nbsp; Thanks!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;First code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy, os, sys&amp;nbsp; # Folder location of maps that need updating. Setup for script tool. Can be changed to hardcoded path. folderpath = arcpy.GetParameterAsText(0)&amp;nbsp; arcpy.env.workspace = r"\\x2x2x2x2.x2x2x2x2x2\???-ocd\Users\my.name\My Documents" for file in arcpy.ListFiles("*.mxd"): &amp;nbsp;&amp;nbsp;&amp;nbsp; print file &amp;nbsp;&amp;nbsp;&amp;nbsp; mxd = arcpy.mapping.MapDocument(os.path.join(folderpath,file)) &amp;nbsp;&amp;nbsp;&amp;nbsp; mxd.findAndReplaceWorkspacePaths(r"\\xxxx.xxxx.xxx", r"\\x2x2x2x2.x2x2x2x2x2") &amp;nbsp;&amp;nbsp;&amp;nbsp; mxd.save() &amp;nbsp;&amp;nbsp;&amp;nbsp; del mxd sys.exit()&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Second code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy, os, sys&amp;nbsp; # Folder location of maps that need updating. Setup for script tool. Can be changed to hardcoded path. folderpath = arcpy.GetParameterAsText(0)&amp;nbsp; arcpy.env.workspace = "\\\\nmfs.local\\akc-ocd\\Users\\jan.benson\\My Documents\\" for file in arcpy.ListFiles("*.mxd"): &amp;nbsp;&amp;nbsp;&amp;nbsp; print file &amp;nbsp;&amp;nbsp;&amp;nbsp; mxd = arcpy.mapping.MapDocument(os.path.join(folderpath,file)) &amp;nbsp;&amp;nbsp;&amp;nbsp; print file &amp;nbsp;&amp;nbsp;&amp;nbsp; oldpath = "\\\\xxxx.xxxx.xxx\\???-ocd\\Users\\my.name\\My Documents\\" &amp;nbsp;&amp;nbsp;&amp;nbsp; newpath = "\\\\x2x2x2x2.x2x2x2x2x2\\???-ocd\\Users\\my.name\\My Documents\\" &amp;nbsp;&amp;nbsp;&amp;nbsp; mxd.findAndReplaceWorkspacePaths(oldpath, newpath) &amp;nbsp;&amp;nbsp;&amp;nbsp; print file &amp;nbsp;&amp;nbsp;&amp;nbsp; mxd.save() &amp;nbsp;&amp;nbsp;&amp;nbsp; del mxd&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 18 Jun 2013 16:02:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/change-path-for-every-mxd-in-a-folder/m-p/583305#M45736</guid>
      <dc:creator>JanBenson</dc:creator>
      <dc:date>2013-06-18T16:02:45Z</dc:date>
    </item>
    <item>
      <title>Re: Change path for every mxd in a folder</title>
      <link>https://community.esri.com/t5/python-questions/change-path-for-every-mxd-in-a-folder/m-p/583306#M45737</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Jan,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I believe the problem is with the arcpy.mapping.MapDocument function.&amp;nbsp; After performing some tests, it doesn't seem like you can use a UNC path with this function.&amp;nbsp; For example, if I run the following code the MXDs will not be updated:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy, os, sys&amp;nbsp; folderpath = r"\\server\temp\python"&amp;nbsp; arcpy.env.workspace = r"\\server\temp\python" for file in arcpy.ListFiles("*.mxd"): &amp;nbsp;&amp;nbsp;&amp;nbsp; mxd = arcpy.mapping.MapDocument(os.path.join(folderpath,file)) &amp;nbsp;&amp;nbsp;&amp;nbsp; oldpath = r"C:\Temp\Python\Test.gdb" &amp;nbsp;&amp;nbsp;&amp;nbsp; newpath = r"\\server\Temp\Python\Test.gdb" &amp;nbsp;&amp;nbsp;&amp;nbsp; mxd.findAndReplaceWorkspacePaths(oldpath, newpath) &amp;nbsp;&amp;nbsp;&amp;nbsp; mxd.save()&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; del mxd&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;However, if I replace the 'folderpath' variable with an absolute path, the code will update the MXDs successfully:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy, os, sys&amp;nbsp; folderpath = r"C:\temp\python"&amp;nbsp; arcpy.env.workspace = r"\\server\temp\python" for file in arcpy.ListFiles("*.mxd"): &amp;nbsp;&amp;nbsp;&amp;nbsp; mxd = arcpy.mapping.MapDocument(os.path.join(folderpath,file)) &amp;nbsp;&amp;nbsp;&amp;nbsp; oldpath = r"C:\Temp\Python\Test.gdb" &amp;nbsp;&amp;nbsp;&amp;nbsp; newpath = r"\\server\Temp\Python\Test.gdb" &amp;nbsp;&amp;nbsp;&amp;nbsp; mxd.findAndReplaceWorkspacePaths(oldpath, newpath) &amp;nbsp;&amp;nbsp;&amp;nbsp; mxd.save()&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; del mxd&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm not sure if this is by design, or if this is a bug.&amp;nbsp; May be worth logging an incident with tech support.&amp;nbsp; Are you able to use an absolute path rather than a UNC path for the folderpath variable?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 18 Jun 2013 18:18:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/change-path-for-every-mxd-in-a-folder/m-p/583306#M45737</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2013-06-18T18:18:52Z</dc:date>
    </item>
    <item>
      <title>Re: Change path for every mxd in a folder</title>
      <link>https://community.esri.com/t5/python-questions/change-path-for-every-mxd-in-a-folder/m-p/583307#M45738</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;If I map the path to a drive, I could use a letter.&amp;nbsp; However we are instructed to use UNC naming convention.&amp;nbsp; The bigger problem is that our old domain no longer exists so that it cannot be mapped.&amp;nbsp; Thanks very much for your help.&amp;nbsp; I will follow up with technical support to see if it is a bug or whether it isdesigned as is.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks again,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Jan&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 18 Jun 2013 19:57:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/change-path-for-every-mxd-in-a-folder/m-p/583307#M45738</guid>
      <dc:creator>JanBenson</dc:creator>
      <dc:date>2013-06-18T19:57:32Z</dc:date>
    </item>
    <item>
      <title>Re: Change path for every mxd in a folder</title>
      <link>https://community.esri.com/t5/python-questions/change-path-for-every-mxd-in-a-folder/m-p/583308#M45739</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am running into the same problem using findAndReplaceWorkspacePaths not being saved after calling mxd.save()&lt;/P&gt;&lt;P&gt;Except all of my paths are absolute paths. No UNC paths being used for map document or connection files.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 13 Apr 2016 18:17:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/change-path-for-every-mxd-in-a-folder/m-p/583308#M45739</guid>
      <dc:creator>Kathleen_Crombez</dc:creator>
      <dc:date>2016-04-13T18:17:04Z</dc:date>
    </item>
  </channel>
</rss>

