Changing path in layer file

1202
3
Jump to solution
10-13-2016 12:52 PM
TychoGranville
Occasional Contributor II

I am sure I am missing something simple (I usually just steal code snippets and try to string them together). I want to change the data source path in a bunch of layer files (I will add in a for… loop once I get this to work). This is a simple layer file, I will also need to update Group layer files

def main():
pass

if __name__ == '__main__':
main()
#Modules
import arcpy
#import string

#Environments
arcpy.env.qualifiedFieldNames = False # Allow unqualified field names
arcpy.env.overwriteOutput

lyr = arcpy.mapping.Layer(r"\\WC-HOMERB\Shared\GIS\Scratch\LayersForWilbur
\LegalParcelData.lyr")

lyr.findAndReplaceWorkspacePaths(r"\\WC-HOMERB\Shared\GIS\GeoDatabase", r"E:
\GISData103\Data")

lyr.save()

and I get this error message:

Help…

0 Kudos
1 Solution

Accepted Solutions
MitchHolley1
MVP Regular Contributor

findAndReplaceWorkspacePath()  not  findAndReplaceWorkspacePaths()...

No 's' on Path

View solution in original post

3 Replies
MitchHolley1
MVP Regular Contributor

findAndReplaceWorkspacePath()  not  findAndReplaceWorkspacePaths()...

No 's' on Path

TychoGranville
Occasional Contributor II

Yep, that did the trick.

Also, for anyone who looks this up in the future, it looks like the target workspace path needs to already exist.

(In my case there is no E:\ drive in our network – I was trying to preconfigure the files on my machine so I could simply copy and paste them to the other one. It is a production machine, so I try to refrain from mucking about on it very much)

Thanks,

Tycho

TychoGranville
Occasional Contributor II

My above comment about the workspace path needing to exist was incorrect. All you need to do is set the validation flag to False. For example,

findAndReplaceWorkspacePath(r"\\WC-HOMERB\Shared\GIS\GeoDatabase", r"E:\GISData103\Data",False)