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.
<SPAN class="keyword token">import</SPAN> arcpy<SPAN class="punctuation token">,</SPAN> os
path <SPAN class="operator token">=</SPAN> r<SPAN class="string token">"C:\layouts"</SPAN>
<SPAN class="keyword token">for</SPAN> fileName <SPAN class="keyword token">in</SPAN> os<SPAN class="punctuation token">.</SPAN>listdir <SPAN class="punctuation token">(</SPAN>path<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
basename<SPAN class="punctuation token">,</SPAN> extension <SPAN class="operator token">=</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>splitext<SPAN class="punctuation token">(</SPAN>fileName<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># select MXD files that do NOT begin with "Copy_of_" - this </SPAN>
<SPAN class="comment token"># prevents the script from updating files that have already been updated</SPAN>
<SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>extension <SPAN class="operator token">==</SPAN> <SPAN class="string token">".mxd"</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">and</SPAN> <SPAN class="punctuation token">(</SPAN>fileName<SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="number token">8</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">!=</SPAN> <SPAN class="string token">"Copy_of_"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
fullPath <SPAN class="operator token">=</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN>path<SPAN class="punctuation token">,</SPAN> fileName<SPAN class="punctuation token">)</SPAN>
mxd <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>mapping<SPAN class="punctuation token">.</SPAN>MapDocument<SPAN class="punctuation token">(</SPAN>fullPath<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN> fullPath
<SPAN class="comment token"># update data sources</SPAN>
mxd<SPAN class="punctuation token">.</SPAN>findAndReplaceWorkspacePaths<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Database Connections\\Server Database NT Auth.sde"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"Database Connections\\HV_Server Database NT Auth.sde"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN> <SPAN class="string token">"\tUpdated: SDE data sources"</SPAN>
<SPAN class="comment token"># check for broken links</SPAN>
brknList <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>mapping<SPAN class="punctuation token">.</SPAN>ListBrokenDataSources<SPAN class="punctuation token">(</SPAN>mxd<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">for</SPAN> brknItem <SPAN class="keyword token">in</SPAN> brknList<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">print</SPAN> <SPAN class="string token">"\tCheck: "</SPAN> <SPAN class="operator token">+</SPAN> brknItem<SPAN class="punctuation token">.</SPAN>name <SPAN class="operator token">+</SPAN> <SPAN class="string token">" data source broken"</SPAN>
<SPAN class="keyword token">if</SPAN> <SPAN class="operator token">not</SPAN> brknList<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">print</SPAN> <SPAN class="string token">"\tCheck: no broken data sources"</SPAN>
<SPAN class="comment token"># save a copy of the MXD</SPAN>
saveACopy_filename <SPAN class="operator token">=</SPAN> <SPAN class="string token">"Copy_of_"</SPAN> <SPAN class="operator token">+</SPAN> fileName
saveACopy_fullpath <SPAN class="operator token">=</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN>path<SPAN class="punctuation token">,</SPAN> saveACopy_filename<SPAN class="punctuation token">)</SPAN>
mxd<SPAN class="punctuation token">.</SPAN>saveACopy<SPAN class="punctuation token">(</SPAN>saveACopy_fullpath<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN> <SPAN class="string token">"\tSaved: "</SPAN> <SPAN class="operator token">+</SPAN> saveACopy_filename
<SPAN class="keyword token">del</SPAN> mxd
<SPAN class="comment token"># delete the original MXD</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>Delete_management<SPAN class="punctuation token">(</SPAN>fullPath<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN> <SPAN class="string token">"\tDeleted: "</SPAN> <SPAN class="operator token">+</SPAN> fullPath<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>