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 os
import arcpy
arcpy.env.workspace = "C:/Locators/Test_LocatorRebuild/"
for loc in arcpy.ListFiles("*.loc"):
print(loc)
arcpy.RebuildAddressLocator_geocoding(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 os
import arcpy
my_workspace = r'C:\Locators\Test_LocatorRebuild\\'
my_locators = [my_workspace + "Streets_Test",
my_workspace + "Structures_Test"]
for loc in my_locators:
print("Rebuilding " + loc)
arcpy.RebuildAddressLocator_geocoding(loc)
print(loc + " rebuild complete")