AnsweredAssumed Answered

Loop through and Rebuild Locators

Question asked by steven_3535 on Dec 5, 2017
Latest reply on Dec 5, 2017 by Dan_Patterson

I'd like to loop through a file folder and rebuild all the locators in it.  Unfortunately, I can't find anything that returns the locator name.  I have been able to loop through using arcpy.ListFiles and find all *.loc files but arcpy.RebuildAddressLocator_geocoding doesn't allow you to use this because of the .loc.  It says it cannot open the locator.  The Esri technical article doesn't apply here because I can rebuild it fine as long as I don't include the .loc.


Throws the error 000005 Could not open address locator

# import system modules
import os
import arcpy

# Set environment settings
arcpy.env.workspace = "C:/Locators/Test_LocatorRebuild/"

for loc in arcpy.ListFiles("*.loc"):


Anyone have any suggestions.


I am currently just adding all locators into the python array and looping through them that way.  It's not ideal but works for now.

# import system modules
import os
import arcpy

#Set my_workspace to the folder location of the locators
my_workspace = r'C:\Locators\Test_LocatorRebuild\\'

#Set my_locators array to include the names of each locator to be rebuilt
my_locators = [my_workspace + "Streets_Test",
               my_workspace + "Structures_Test"]

#Loop through the array and rebuild the address locators
for loc in my_locators:
    print("Rebuilding " + loc)
    print(loc + " rebuild complete")