How can one change the source data paths for every layer file in folder X using arcpy?
I've followed Updating and fixing data sources with arcpy.mapping as best I can, yet all I get is an unhelpful Runtime error <type 'exceptions.ValueError'>: Layer: Unexpected error
which doesn't tell me enough to troubleshoot what's wrong or missing.
Heres the code (simplified to test a single layer file):
import arcpy, os
fname = r'K:\Layers\xxx.lyr'
lyr = arcpy.mapping.Layer(fname)
oldpath = lyr.workspacePath
print 'oldpath: ', oldpath
lyr.findAndReplaceWorkspacePath(oldpath, r'C:\some\other.gdb')
print 'newpath: ', lyr.workspacePath
and the results:
oldpath: K:\Canvec_Utility\Temp.gdb
Traceback (most recent call last):
File "x10x.py", line 12, in <module>
lyr.findAndReplaceWorkspacePath(oldpath, r'C:\some\other.gdb')
File "C:\ESRI\ArcGIS\Desktop10.0\arcpy\arcpy\utils.py", line 181, in fn_
return fn(*args, **kw)
File "C:\ESRI\ArcGIS\Desktop10.0\arcpy\arcpy\_mapping.py", line 601, in findAndReplaceWorkspacePath
return convertArcObjectToPythonObject(self._arc_object.findAndReplaceWorkspacePath(*gp_fixargs((find_workspace_path, replace_workspace_path, validate), True
)))
ValueError: Layer: Unexpected error
((moved 'update' section into an answer))
Runtime error...
quoted above is from the interactive python shell in Arccatalog, which doesn't give a traceback. The results with traceback are copied from a command shell.