AnsweredAssumed Answered

Replace parts of a data source string in Layer files?

Question asked by JB1234510 on Feb 9, 2015
Latest reply on Feb 11, 2015 by recurvata

Why does this code replace only things like c:\temp\data through c:\tempXXX\data and not the beginning of c:\temp\data\1\2\3 ?


import arcpy, os
# Pfade definieren
folderPath = r"R:\SG-C\8850.20-6 FFH-Gebiete\04 MaP\7218-341_Calwer_Heckengaeu"
oldPath = r"R:\natura 2000\8847.04 MaP\7218-341_Calwer_Heckengäu"
# mxd definieren
path = r"R:\SG-C\8850.20-6 FFH-Gebiete\04 MaP\7218-341_Calwer_Heckengaeu\7218341.mxd"
mxd = arcpy.mapping.MapDocument(path)  
for df in arcpy.mapping.ListDataFrames(mxd):  
    for lyr in arcpy.mapping.ListLayers(mxd): 
        print (lyr)
        lyr.findAndReplaceWorkspacePath(oldPath, folderPath, "")
del mxd