I have a script to replace links for pictures from an old folder to a new folder.

Truncates the link to '\env.gov.ab.ca\Parks\CityWorks\Referenced\Franchere_Bay_PRA', what I want is '\\env.gov.ab.ca\Parks\CityWorks\Referenced\Franchere_Bay_PRA'

 import arcpy
    arcpy.env.workspace = "C:/Users/vincent.law/Documents/CW/CW_Franchere_Bay_PRA.gdb"

    a2 = """def rep_field(in_fld, rep_value):
        targets = ['W:\OPERATIONS\CPI\Asset_Management\GNSS Projects\Parks Inventory\Franchere Bay PRA\FRANCHEREBAYPRA-20150804-CD~files','W:\OPERATIONS\CPI\Asset_Management\GNSS Projects\Parks Inventory\Franchere Bay PRA\FRANCHEREBAYPRA_AUG4_2015_JL~files','W:\OPERATIONS\CPI\Asset_Management\GNSS Projects\Parks Inventory\Franchere Bay PRA\FRANCHERE BAY PRA-04-08-15-TCN~files','W:\OPERATIONS\CPI\Asset_Management\GNSS Projects\Parks Inventory\Franchere Bay PRA\FRANCHERE BAY PRA_2015-08-04_CS~files']
        for targ in targets:
            in_fld = in_fld.replace(targ, rep_value)
        return in_fld"""

    a1 = """rep_field (!Picture!,'\\\env.gov.ab.ca\Parks\CityWorks\Referenced\Franchere_Bay_PRA')"""

    arcpy.CalculateField_management(in_table="Bench_and_Table", field="Picture", expression = a1, expression_type="PYTHON_9.3", code_block = a2)

You either have to put a r in front of the path name so that python doesn't think that the \ is a special character. Try this instead.


You could also try:


You can look into the os.path module as well. There's a similar question on Stack Overflow.

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.