I am trying to repath multiple feature classes within an mxd. The new feature classes all come from various databases and folders but the only change in the file path is in the drive name. For example C:\features\points needs to be repathed to N:\features\points

I have read over this page: http://desktop.arcgis.com/en/arcmap/10.3/analyze/arcpy-mapping/updatingandfixingdatasources.htm but didnt see any examples pertaining to partial name changes.

This is what I have so far but I need some advice figuring out how to update part of the path without hard coding each new path.

import arcpy
mxd = arcpy.mapping.MapDocument("CURRENT")
mxd.findAndReplaceWorkspacePaths(r"C:\features\points", r"N:\features\points")
del mxd
  • Each layer has a source path property, with a setter and a getter. You can't just alter part of the path. You can use a relative path, but that only applies to data on the same logical volume as the map document (and it might cause issues in publishing). – Vince Jan 12 '18 at 21:42

You could loop through each layer, find the current source into a variable currentsource, and then create a new variable newsource by modifying the value from the currentsource variable.

You can then set the new location by using the mxd.findAndReplaceWorkspacePaths(), or one of the other similar tools, using the currentsource and newsource variables for the find_workspace_path, replace_workspace_path properties.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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