1

Is there a way I can find and replace all layerfile paths in a folder?

I have over 150 layer files that have incorrect paths after a server migration changed the path of the layerfiles. I have found ways to change the layerfile path within an mxd but nothing on how to change all within a specific folder.

1
  • Please specify the version of your ArcGIS or add some appropriate tags
    – Basile
    May 29, 2018 at 16:34

2 Answers 2

3

You can change all or just a part of links in your mxd this way:

  1. Open ArcCatalog and navigate to your mxd file
  2. Right-click and select "Set data sources"
  3. Highlight the ones you need to change or click "Select All"
  4. Click "Replace" or "Replace All" and specify a new path(s).
  5. Click "Ok" - this will save a copy of your .mxd file with updated paths
3
  • I am looking to replace all paths within a folder not an mxd.
    – Bowser
    May 29, 2018 at 16:54
  • What do you mean by "replace paths within a folder"? Is this folder referenced in a project?
    – Basile
    May 29, 2018 at 16:58
  • I have 150 layerfiles in a folder on our server. They are not referenced currently in any mxd but the data the layerfile references has been moved. I need to redirect the layerfile path to the new location on server.
    – Bowser
    May 29, 2018 at 17:05
1

There are lots of examples of doing this using arcpy. Here is some quick code I have used in the past for mass updating .mxd data sources. You should be easily able to adapt it to layer files using the examples here:https://pro.arcgis.com/en/pro-app/arcpy/mapping/updatingandfixingdatasources.htm

import arcpy     
arcpy.env.workspace = r"C:\Temp\mxds"  
new_location  = r"C:\Temp\Newsourcedata"  
for file in arcpy.ListFiles("*.mxd"):
    mxd = arcpy.mapping.MapDocument(file)  
    mxd.findAndReplaceWorkspacePaths(" " , new_location )  
    mxd.save()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.