<?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: Find and Replace Data Source Across Multiple MXDs in a Folder in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/find-and-replace-data-source-across-multiple-mxds/m-p/453677#M35620</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;It is not getting your parameters, are you passing them along with the command line.&lt;BR /&gt;&lt;BR /&gt;If you are not running from a GP tool, you need to either pass the parameters as arguments (Python D:\scriptfile.py d:\myfolder myData OutPut NewSource) or code the paths (folderPath=r"C:\arcgisserver\local_data\").&lt;BR /&gt;&lt;BR /&gt;I normally just put the path to my data in the script and run it.&lt;BR /&gt;&lt;BR /&gt;R_&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks I am passing the parms through a GP tool. I will try hard coding to see if I can get this to work. Any suggestion on where to search to learn more about debugging why a parameter being passed via a GP tool isn't working correctly?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 24 Jun 2013 13:29:33 GMT</pubDate>
    <dc:creator>TerryHiggins1</dc:creator>
    <dc:date>2013-06-24T13:29:33Z</dc:date>
    <item>
      <title>Find and Replace Data Source Across Multiple MXDs in a Folder</title>
      <link>https://community.esri.com/t5/python-questions/find-and-replace-data-source-across-multiple-mxds/m-p/453667#M35610</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Ok - I'm a beginner trying to figure out how to modify one of the scripts I located. The original script is designed to search a folder with MXDs and print out report off all the MXDs that contain a particular data source. I want to take this one step further - so if the data source is located then I would like to replace it. I tried adding this to the sample code -&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; lyr.findAndReplaceWorkspacePath("dateSource", "newSource") #TH Testing&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; mxd.save() #TH Testing&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The script runs but the change doesn't take place or if it does it isn't saved.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Any help would be great. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;# Author:&amp;nbsp; ESRI
# Date:&amp;nbsp;&amp;nbsp;&amp;nbsp; July 5, 2010
# Version: ArcGIS 10.0 Final
# Purpose: This script will iterate through each MXD in a folder and report the
#&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; name of each map document that contains a specific data source.&amp;nbsp; The
#&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; script is intended to run from a script tool that requires three
#&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; input parameters:
#&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1) A folder that contains the set of MXDs that will be searched,
#&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2) A data source that you want to search for,
#&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 3) An output text file.
#&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; The resulting text file will automatically open.

import arcpy, datetime, os

try:

&amp;nbsp; #Read input parameters from GP dialog
&amp;nbsp; folderPath = arcpy.GetParameterAsText(0)
&amp;nbsp; dataSource = arcpy.GetParameterAsText(1)
&amp;nbsp; output = arcpy.GetParameterAsText(3)
&amp;nbsp; newSource = arcpy.GetParameterAsText(2)

&amp;nbsp; #Create an output file
&amp;nbsp; outFile = open(output, "w")

&amp;nbsp; #Report header
&amp;nbsp; outFile.write("Data Source Report: \n")
&amp;nbsp; outFile.write("\n")
&amp;nbsp; outFile.write("This report summarizes the names of all map documents within a folder that\n")
&amp;nbsp; outFile.write("contain a specific data source. \n")
&amp;nbsp; outFile.write("\n")
&amp;nbsp; outFile.write("Folder location: " + folderPath + "\n")
&amp;nbsp; outFile.write("\n")
&amp;nbsp; outFile.write("Date: " + str(datetime.datetime.today().strftime("%B %d, %Y")) + "\n")

&amp;nbsp; #Loop through ech MXD file
&amp;nbsp; mCnt = 0
&amp;nbsp; for filename in os.listdir(folderPath):
&amp;nbsp;&amp;nbsp;&amp;nbsp; fullpath = os.path.join(folderPath, filename)
&amp;nbsp;&amp;nbsp;&amp;nbsp; if os.path.isfile(fullpath):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if filename.lower().endswith(".mxd"):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #Reference MXD
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd = arcpy.mapping.MapDocument(fullpath)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #Determine if the data source exists within the data frames/map document 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #If exist then update the datasource - TH Testing 06/05/2013
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sCnt = 0
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for df in arcpy.mapping.ListDataFrames(mxd):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; layerList = []
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for lyr in arcpy.mapping.ListLayers(mxd, "", df):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if lyr.supports("dataSource"):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if lyr.dataSource == dataSource:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr.findAndReplaceWorkspacePath("dateSource", "newSource") #TH Testing
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd.save() #TH Testing
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mCnt = 1
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sCnt = sCnt + 1
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; layerList.append(lyr.name)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if sCnt == 1:&amp;nbsp; #Write the MXD header once
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; outFile.write("\n")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; outFile.write("\n")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; outFile.write("---------------------------------------------------------------------------------- \n")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; outFile.write(" MAPDOCUMENT: " + os.path.basename(mxd.filePath) + "\n")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; outFile.write("---------------------------------------------------------------------------------- \n")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sCnt = sCnt + 1 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if len(layerList) &amp;gt; 0: #Write the data frame name once
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; outFile.write("\n")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; outFile.write("\t Data Frame: " + df.name + "\n")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for lyr in layerList: #Write each layer name
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; outFile.write("\n")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; outFile.write("\t\t Layer: " + lyr + "\n")

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; del mxd
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp; if mCnt == 0:
&amp;nbsp;&amp;nbsp;&amp;nbsp; outFile.write("\n")
&amp;nbsp;&amp;nbsp;&amp;nbsp; outFile.write("\n")
&amp;nbsp;&amp;nbsp;&amp;nbsp; outFile.write("---------------------------------------------------------------------------------- \n")
&amp;nbsp;&amp;nbsp;&amp;nbsp; outFile.write("&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; NO DATA SOURCES FOUND \n")
&amp;nbsp;&amp;nbsp;&amp;nbsp; outFile.write("---------------------------------------------------------------------------------- \n")
&amp;nbsp; outFile.close()

&amp;nbsp; #Open the resulting text file
&amp;nbsp; os.startfile(output)

&amp;nbsp; #Delete variable references
&amp;nbsp; del folderPath, dataSource, output, outFile, fullpath

except Exception, e:
&amp;nbsp; import traceback
&amp;nbsp; map(arcpy.AddError, traceback.format_exc().split("\n"))
&amp;nbsp; arcpy.AddError(str(e))&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 05 Jun 2013 20:28:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/find-and-replace-data-source-across-multiple-mxds/m-p/453667#M35610</guid>
      <dc:creator>TerryHiggins1</dc:creator>
      <dc:date>2013-06-05T20:28:24Z</dc:date>
    </item>
    <item>
      <title>Re: Find and Replace Data Source Across Multiple MXDs in a Folder</title>
      <link>https://community.esri.com/t5/python-questions/find-and-replace-data-source-across-multiple-mxds/m-p/453668#M35611</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have not tried this with python, however, there is/was a bug in the Set Data Source(s) in ArcGIS.&amp;nbsp; Don't know if it applies to the arcpy tool as well, but, if your data is UNC pathed, the Set Data Source does not work correctly.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Not anywhere I can test to see if they have fixed this yet, but thought I'd throw it out there in case you are using UNC paths,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; R_&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 05 Jun 2013 22:31:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/find-and-replace-data-source-across-multiple-mxds/m-p/453668#M35611</guid>
      <dc:creator>RhettZufelt</dc:creator>
      <dc:date>2013-06-05T22:31:05Z</dc:date>
    </item>
    <item>
      <title>Re: Find and Replace Data Source Across Multiple MXDs in a Folder</title>
      <link>https://community.esri.com/t5/python-questions/find-and-replace-data-source-across-multiple-mxds/m-p/453669#M35612</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You are not saving the changes to the mxd.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Try:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;mxd.save()&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;or&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;mxd.saveACopy(new path)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;These lines would need to be at the same indent space as the mxd variable.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Jeff&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 06 Jun 2013 13:45:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/find-and-replace-data-source-across-multiple-mxds/m-p/453669#M35612</guid>
      <dc:creator>JeffBarrette</dc:creator>
      <dc:date>2013-06-06T13:45:55Z</dc:date>
    </item>
    <item>
      <title>Re: Find and Replace Data Source Across Multiple MXDs in a Folder</title>
      <link>https://community.esri.com/t5/python-questions/find-and-replace-data-source-across-multiple-mxds/m-p/453670#M35613</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Jeff thank you for the response - however I thought this line that I inserted is handling the save? &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;lyr.findAndReplaceWorkspacePath("dateSource", "newSource") #TH Testing&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd.save() #TH Testing&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 07 Jun 2013 17:00:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/find-and-replace-data-source-across-multiple-mxds/m-p/453670#M35613</guid>
      <dc:creator>TerryHiggins1</dc:creator>
      <dc:date>2013-06-07T17:00:49Z</dc:date>
    </item>
    <item>
      <title>Re: Find and Replace Data Source Across Multiple MXDs in a Folder</title>
      <link>https://community.esri.com/t5/python-questions/find-and-replace-data-source-across-multiple-mxds/m-p/453671#M35614</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt; Ok - I'm a beginner trying to figure out how to modify one of the scripts I located. The original script is designed to search a folder with MXDs and print out report off all the MXDs that contain a particular data source. I want to take this one step further - so if the data source is located then I would like to replace it. I tried adding this to the sample code -&amp;nbsp; &lt;BR /&gt; &lt;BR /&gt; lyr.findAndReplaceWorkspacePath("dateSource", "newSource") #TH Testing&amp;nbsp; &lt;BR /&gt; mxd.save() #TH Testing&amp;nbsp; &lt;BR /&gt; &lt;BR /&gt;The script runs but the change doesn't take place or if it does it isn't saved.&amp;nbsp; &lt;BR /&gt;Any help would be great.&amp;nbsp;&amp;nbsp; &lt;BR /&gt; &lt;BR /&gt; &lt;BR /&gt; &lt;PRE class="lia-code-sample line-numbers language-none"&gt;# Author:&amp;nbsp; ESRI
# Date:&amp;nbsp;&amp;nbsp;&amp;nbsp; July 5, 2010
# Version: ArcGIS 10.0 Final
# Purpose: This script will iterate through each MXD in a folder and report the
#&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; name of each map document that contains a specific data source.&amp;nbsp; The
#&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; script is intended to run from a script tool that requires three
#&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; input parameters:
#&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1) A folder that contains the set of MXDs that will be searched,
#&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2) A data source that you want to search for,
#&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 3) An output text file.
#&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; The resulting text file will automatically open.

import arcpy, datetime, os

try:

&amp;nbsp; #Read input parameters from GP dialog
&amp;nbsp; folderPath = arcpy.GetParameterAsText(0)
&amp;nbsp; dataSource = arcpy.GetParameterAsText(1)
&amp;nbsp; output = arcpy.GetParameterAsText(3)
&amp;nbsp; newSource = arcpy.GetParameterAsText(2)

&amp;nbsp;&amp;nbsp; #Loop through ech MXD file
&amp;nbsp; mCnt = 0
&amp;nbsp; for filename in os.listdir(folderPath):
&amp;nbsp;&amp;nbsp;&amp;nbsp; fullpath = os.path.join(folderPath, filename)
&amp;nbsp;&amp;nbsp;&amp;nbsp; if os.path.isfile(fullpath):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if filename.lower().endswith(".mxd"):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #Reference MXD
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd = arcpy.mapping.MapDocument(fullpath)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #Determine if the data source exists within the data frames/map document 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #If exist then update the datasource - TH Testing 06/05/2013
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sCnt = 0
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for df in arcpy.mapping.ListDataFrames(mxd):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; layerList = []
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for lyr in arcpy.mapping.ListLayers(mxd, "", df):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if lyr.supports("dataSource"):
 &lt;SPAN style="color:&amp;quot;#FF0000&amp;quot;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if lyr.dataSource == dataSource:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr.findAndReplaceWorkspacePath("dateSource", "newSource")&lt;/SPAN&gt; #TH Testing
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd.save() #TH Testing
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mCnt = 1
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sCnt = sCnt + 1
))&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Perhaps its due to trying to set it to a variable that hasn't been defined?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Not sure the exact syntax for that command, but dateSource &amp;lt;&amp;gt; dataSource&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;R_&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 20:13:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/find-and-replace-data-source-across-multiple-mxds/m-p/453671#M35614</guid>
      <dc:creator>RhettZufelt</dc:creator>
      <dc:date>2021-12-11T20:13:50Z</dc:date>
    </item>
    <item>
      <title>Re: Find and Replace Data Source Across Multiple MXDs in a Folder</title>
      <link>https://community.esri.com/t5/python-questions/find-and-replace-data-source-across-multiple-mxds/m-p/453672#M35615</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Perhaps its due to trying to set it to a variable that hasn't been defined?&lt;BR /&gt;&lt;BR /&gt;Not sure the exact syntax for that command, but dateSource &amp;lt;&amp;gt; dataSource&lt;BR /&gt;&lt;BR /&gt;R_&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks I didn't catch that typo. Those seem to get me! Will give it a try. Thanks again.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Jun 2013 13:24:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/find-and-replace-data-source-across-multiple-mxds/m-p/453672#M35615</guid>
      <dc:creator>TerryHiggins1</dc:creator>
      <dc:date>2013-06-20T13:24:13Z</dc:date>
    </item>
    <item>
      <title>Re: Find and Replace Data Source Across Multiple MXDs in a Folder</title>
      <link>https://community.esri.com/t5/python-questions/find-and-replace-data-source-across-multiple-mxds/m-p/453673#M35616</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Thanks I didn't catch that typo. Those seem to get me! Will give it a try. Thanks again.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Ok I corrected the syntax in regards to the typo. The script ran and correctly produced the report identifying the mxd within the folder with the datasource specified - however it did not update the data source. Any additional ideas on what I might be missing here?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Jun 2013 14:12:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/find-and-replace-data-source-across-multiple-mxds/m-p/453673#M35616</guid>
      <dc:creator>TerryHiggins1</dc:creator>
      <dc:date>2013-06-20T14:12:04Z</dc:date>
    </item>
    <item>
      <title>Re: Find and Replace Data Source Across Multiple MXDs in a Folder</title>
      <link>https://community.esri.com/t5/python-questions/find-and-replace-data-source-across-multiple-mxds/m-p/453674#M35617</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import arcpy, datetime, os

try:

&amp;nbsp; #Read input parameters from GP dialog
&amp;nbsp; folderPath = arcpy.GetParameterAsText(0)
&amp;nbsp; dataSource = arcpy.GetParameterAsText(1)
&amp;nbsp; output = arcpy.GetParameterAsText(3)
&amp;nbsp; newSource = arcpy.GetParameterAsText(2)

 

 print&amp;nbsp; folderPath
 print&amp;nbsp; dataSource
 print&amp;nbsp; output 
 print&amp;nbsp; newSource&amp;nbsp;&amp;nbsp; 

#Loop through ech MXD file
&amp;nbsp; mCnt = 0
&amp;nbsp; for filename in os.listdir(folderPath):
&amp;nbsp;&amp;nbsp;&amp;nbsp; fullpath = os.path.join(folderPath, filename)
&amp;nbsp;&amp;nbsp;&amp;nbsp; if os.path.isfile(fullpath):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if filename.lower().endswith(".mxd"):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #Reference MXD
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd = arcpy.mapping.MapDocument(fullpath)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #Determine if the data source exists within the data frames/map document 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #If exist then update the datasource - TH Testing 06/05/2013
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sCnt = 0
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for df in arcpy.mapping.ListDataFrames(mxd):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; layerList = []
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for lyr in arcpy.mapping.ListLayers(mxd, "", df):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if lyr.supports("dataSource"):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if lyr.dataSource == dataSource:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr.findAndReplaceWorkspacePath("dateSource", "newSource") #TH Testing
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd.save() #TH Testing
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mCnt = 1
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sCnt = sCnt + 1
))
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Are you sure your variables are getting set correctly? What happens if you add the changes above in blue?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;R_&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 16:29:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/find-and-replace-data-source-across-multiple-mxds/m-p/453674#M35617</guid>
      <dc:creator>RhettZufelt</dc:creator>
      <dc:date>2021-12-12T16:29:47Z</dc:date>
    </item>
    <item>
      <title>Re: Find and Replace Data Source Across Multiple MXDs in a Folder</title>
      <link>https://community.esri.com/t5/python-questions/find-and-replace-data-source-across-multiple-mxds/m-p/453675#M35618</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt; &lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import arcpy, datetime, os

try:

&amp;nbsp; #Read input parameters from GP dialog
&amp;nbsp; folderPath = arcpy.GetParameterAsText(0)
&amp;nbsp; dataSource = arcpy.GetParameterAsText(1)
&amp;nbsp; output = arcpy.GetParameterAsText(3)
&amp;nbsp; newSource = arcpy.GetParameterAsText(2)

 
&lt;SPAN style="color:&amp;quot;#0000FF&amp;quot;;"&gt;
 print&amp;nbsp; folderPath
 print&amp;nbsp; dataSource
 print&amp;nbsp; output 
 print&amp;nbsp; newSource &lt;/SPAN&gt;&amp;nbsp; 

#Loop through ech MXD file
&amp;nbsp; mCnt = 0
&amp;nbsp; for filename in os.listdir(folderPath):
&amp;nbsp;&amp;nbsp;&amp;nbsp; fullpath = os.path.join(folderPath, filename)
&amp;nbsp;&amp;nbsp;&amp;nbsp; if os.path.isfile(fullpath):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if filename.lower().endswith(".mxd"):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #Reference MXD
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd = arcpy.mapping.MapDocument(fullpath)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #Determine if the data source exists within the data frames/map document 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #If exist then update the datasource - TH Testing 06/05/2013
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sCnt = 0
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for df in arcpy.mapping.ListDataFrames(mxd):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; layerList = []
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for lyr in arcpy.mapping.ListLayers(mxd, "", df):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if lyr.supports("dataSource"):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if lyr.dataSource == dataSource:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr.findAndReplaceWorkspacePath("dateSource", "newSource") #TH Testing
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd.save() #TH Testing
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mCnt = 1
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sCnt = sCnt + 1
))
&lt;/PRE&gt; &lt;BR /&gt; &lt;BR /&gt;Are you sure your variables are getting set correctly? What happens if you add the changes above in blue?&amp;nbsp; &lt;BR /&gt; &lt;BR /&gt;R_&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I entered in the lines you recommended however none of them printed... not sure what I am doing incorrect.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 20:13:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/find-and-replace-data-source-across-multiple-mxds/m-p/453675#M35618</guid>
      <dc:creator>TerryHiggins1</dc:creator>
      <dc:date>2021-12-11T20:13:52Z</dc:date>
    </item>
    <item>
      <title>Re: Find and Replace Data Source Across Multiple MXDs in a Folder</title>
      <link>https://community.esri.com/t5/python-questions/find-and-replace-data-source-across-multiple-mxds/m-p/453676#M35619</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;It is not getting your parameters, are you passing them along with the command line.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If you are not running from a GP tool, you need to either pass the parameters as arguments (Python D:\scriptfile.py d:\myfolder myData OutPut NewSource) or code the paths (folderPath=r"C:\arcgisserver\local_data\").&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I normally just put the path to my data in the script and run it.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;R_&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Jun 2013 21:36:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/find-and-replace-data-source-across-multiple-mxds/m-p/453676#M35619</guid>
      <dc:creator>RhettZufelt</dc:creator>
      <dc:date>2013-06-20T21:36:31Z</dc:date>
    </item>
    <item>
      <title>Re: Find and Replace Data Source Across Multiple MXDs in a Folder</title>
      <link>https://community.esri.com/t5/python-questions/find-and-replace-data-source-across-multiple-mxds/m-p/453677#M35620</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;It is not getting your parameters, are you passing them along with the command line.&lt;BR /&gt;&lt;BR /&gt;If you are not running from a GP tool, you need to either pass the parameters as arguments (Python D:\scriptfile.py d:\myfolder myData OutPut NewSource) or code the paths (folderPath=r"C:\arcgisserver\local_data\").&lt;BR /&gt;&lt;BR /&gt;I normally just put the path to my data in the script and run it.&lt;BR /&gt;&lt;BR /&gt;R_&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks I am passing the parms through a GP tool. I will try hard coding to see if I can get this to work. Any suggestion on where to search to learn more about debugging why a parameter being passed via a GP tool isn't working correctly?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 24 Jun 2013 13:29:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/find-and-replace-data-source-across-multiple-mxds/m-p/453677#M35620</guid>
      <dc:creator>TerryHiggins1</dc:creator>
      <dc:date>2013-06-24T13:29:33Z</dc:date>
    </item>
    <item>
      <title>Re: Find and Replace Data Source Across Multiple MXDs in a Folder</title>
      <link>https://community.esri.com/t5/python-questions/find-and-replace-data-source-across-multiple-mxds/m-p/453678#M35621</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi, &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I asked a similar question &lt;/SPAN&gt;&lt;A href="http://gis.stackexchange.com/questions/64064/python-change-sde-data-source-for-mxds-in-specific-folder" rel="nofollow noopener noreferrer" target="_blank"&gt;here&lt;/A&gt;&lt;SPAN&gt; with the resulting code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import os, arcpy

folderPath = "G:\GIS\Services\Test"
for fileName in [x for x in os.listdir(folderPath) if os.path.splitext(x)[1] == ".mxd"]:
&amp;nbsp;&amp;nbsp;&amp;nbsp; fullPath = os.path.join(folderPath, fileName)
&amp;nbsp;&amp;nbsp;&amp;nbsp; if os.path.isfile(fullPath):&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd = arcpy.mapping.MapDocument(fullPath)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "MXD: " + fileName
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.env.workspace = fullPath&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd.replaceWorkspaces("", "NONE", r"Database Connections\Connection to gisserver.sde","SDE_WORKSPACE")&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd.save()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; del mxd
&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "error! {0} failed to be replaced".format(fullPath)
print "successfully changed data sources"&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 20:13:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/find-and-replace-data-source-across-multiple-mxds/m-p/453678#M35621</guid>
      <dc:creator>LaurenYee</dc:creator>
      <dc:date>2021-12-11T20:13:55Z</dc:date>
    </item>
    <item>
      <title>Re: Find and Replace Data Source Across Multiple MXDs in a Folder</title>
      <link>https://community.esri.com/t5/python-questions/find-and-replace-data-source-across-multiple-mxds/m-p/453679#M35622</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Thanks I am passing the parms through a GP tool. I will try hard coding to see if I can get this to work. Any suggestion on where to search to learn more about debugging why a parameter being passed via a GP tool isn't working correctly?&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I rarely use tools/models from within ArcMap other than to write my initial python code for me, so probably not the best to answer this question.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;However, the few that I do run through ArcMap/Toolbox, I right-click on the model script itself, select properties, and parameters.&amp;nbsp; this is where you set the parameters that get passed to arcpy when run.&amp;nbsp; Can hard code, browse button, etc.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Another way to pass parameters is as arguments.&amp;nbsp;&amp;nbsp; C:\pythonpath\python.exe scriptfile.py arg1 arg2 arg3&amp;nbsp; (which would be parameter(0), (1), etc).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;However, I normally just hard code it in the python script, as it is either static, OR, python tools can iterate/parse/filter/etc. to get the paramaters I need.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;R_&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 24 Jun 2013 17:36:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/find-and-replace-data-source-across-multiple-mxds/m-p/453679#M35622</guid>
      <dc:creator>RhettZufelt</dc:creator>
      <dc:date>2013-06-24T17:36:09Z</dc:date>
    </item>
    <item>
      <title>Re: Find and Replace Data Source Across Multiple MXDs in a Folder</title>
      <link>https://community.esri.com/t5/python-questions/find-and-replace-data-source-across-multiple-mxds/m-p/453680#M35623</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;I rarely use tools/models from within ArcMap other than to write my initial python code for me, so probably not the best to answer this question.&lt;BR /&gt;&lt;BR /&gt;However, the few that I do run through ArcMap/Toolbox, I right-click on the model script itself, select properties, and parameters.&amp;nbsp; this is where you set the parameters that get passed to arcpy when run.&amp;nbsp; Can hard code, browse button, etc.&lt;BR /&gt;&lt;BR /&gt;Another way to pass parameters is as arguments.&amp;nbsp;&amp;nbsp; C:\pythonpath\python.exe scriptfile.py arg1 arg2 arg3&amp;nbsp; (which would be parameter(0), (1), etc).&lt;BR /&gt;&lt;BR /&gt;However, I normally just hard code it in the python script, as it is either static, OR, python tools can iterate/parse/filter/etc. to get the paramaters I need.&lt;BR /&gt;&lt;BR /&gt;R_&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;This is how I intially was passing the parameter, however I hard coded them as you suggested then ran the process. I did get the values I expected to print with the print statement but I still did not have the changes saved. The interesting thing - after I ran it the first time and then checked the mxd to see if the source was changed, and it wasn't I ran the process again. This time however the original datasource created a message stating it was not found. I am so baffled by this and not sure where to go next? &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;If the issue was a problem with how I wrote the save then running the script again should have still found the original datasource, but it didn't.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any additional thoughts on this?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;In the meantime I am gong to create a new test set and try the hard coded concept.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 26 Jun 2013 14:03:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/find-and-replace-data-source-across-multiple-mxds/m-p/453680#M35623</guid>
      <dc:creator>TerryHiggins1</dc:creator>
      <dc:date>2013-06-26T14:03:48Z</dc:date>
    </item>
  </channel>
</rss>

