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
<SPAN class="comment token"># import system modules</SPAN>
<SPAN class="keyword token">import</SPAN> os
<SPAN class="keyword token">import</SPAN> arcpy
<SPAN class="comment token"># Set environment settings</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>workspace <SPAN class="operator token">=</SPAN> <SPAN class="string token">"C:/Locators/Test_LocatorRebuild/"</SPAN>
<SPAN class="keyword token">for</SPAN> loc <SPAN class="keyword token">in</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>ListFiles<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"*.loc"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN>loc<SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>RebuildAddressLocator_geocoding<SPAN class="punctuation token">(</SPAN>loc<SPAN class="punctuation token">)</SPAN>
<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
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.
<SPAN class="comment token"># import system modules</SPAN>
<SPAN class="keyword token">import</SPAN> os
<SPAN class="keyword token">import</SPAN> arcpy
<SPAN class="comment token">#Set my_workspace to the folder location of the locators</SPAN>
my_workspace <SPAN class="operator token">=</SPAN> r<SPAN class="string token">'C:\Locators\Test_LocatorRebuild\\'</SPAN>
<SPAN class="comment token">#Set my_locators array to include the names of each locator to be rebuilt</SPAN>
my_locators <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN>my_workspace <SPAN class="operator token">+</SPAN> <SPAN class="string token">"Streets_Test"</SPAN><SPAN class="punctuation token">,</SPAN>
my_workspace <SPAN class="operator token">+</SPAN> <SPAN class="string token">"Structures_Test"</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="comment token">#Loop through the array and rebuild the address locators</SPAN>
<SPAN class="keyword token">for</SPAN> loc <SPAN class="keyword token">in</SPAN> my_locators<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Rebuilding "</SPAN> <SPAN class="operator token">+</SPAN> loc<SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>RebuildAddressLocator_geocoding<SPAN class="punctuation token">(</SPAN>loc<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN>loc <SPAN class="operator token">+</SPAN> <SPAN class="string token">" rebuild complete"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>