What would be the proper syntax if I want to use the "replace" python function in ArcMap field calculator to replace a file path with a new one.
for example the current links path is W:\folder name\file name I want to replace just the "W:\" with "V:\" Any help would be great. Thanks
Solved! Go to Solution.
Hi Erik,
You could use the following:
!Links!.replace("W:", "V:")
where 'Links' is the field name.
Hi Erik,
You could use the following:
!Links!.replace("W:", "V:")
where 'Links' is the field name.
Thanks Jake.
Jake
would you possibly know how I would use python to replace "\" with "/" this occurrence happens in the middle of the links string. So for example: V:\folder\folder\filename
I was able to get the "\" replaced up to the last one by using the replace function in arcmap by doing this:
!LINKS!.replace("\foldername" , "/foldername")
However when i try to replace the text ending in the backslash it errors out. For example:
!LINKS!.replace("foldername\" , "foldername/")
Any suggestion would be great help. Thanks.
Maybe you should use some os.path methods:
import os path = r"V:/blah\blah/blah\blah" print os.path.normcase(path) # >> v:\blah\blah\blah\blah path = r"V://blah\blah/blah\\blah" print os.path.normpath(path) # >> V:\blah\blah\blah\blah
Xander
Thanks for your time and help. Excuse my ignorance, but I have just a little experience in python. So I want to do this on a field in one of our layers that contains these file path to be used to access links through our web maps. Is it still possible to use the method you showed above. And do I do it inside python in arcmap from the geoprocessing toolbar. Thanks again for your help.
Try using double back slashes. Ex:
!Links!.replace("W:\\folder\\folder", "V:\\folder2\\folder2")
Jake/Xander
Thanks guys for your help. I just ended up exporting the layer to dbf and made the changes in excel and then rejoined back to the layer in ArcMap and did a field calculation. Much easier for me that way. But just wanted to say thanks for your help and suggestions. Trying to get backslashes changed to forward slashes is still a little beyond my skill set with python.