List .gdb in a folder location and use the .gdb as a variable?
Are you asking about a way to walk through a directory and find gdb's? One way:
<SPAN class="keyword token">import</SPAN> arcpy<SPAN class="punctuation token">,</SPAN> os <SPAN class="keyword token">from</SPAN> arcpy <SPAN class="keyword token">import</SPAN> env workspace <SPAN class="operator token">=</SPAN> r<SPAN class="string token">"C:\Path\to\explore"</SPAN> <SPAN class="keyword token">for</SPAN> dirpath<SPAN class="punctuation token">,</SPAN> dirnames<SPAN class="punctuation token">,</SPAN> filenames <SPAN class="keyword token">in</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>da<SPAN class="punctuation token">.</SPAN>Walk<SPAN class="punctuation token">(</SPAN>workspace<SPAN class="punctuation token">,</SPAN> datatype<SPAN class="operator token">=</SPAN><SPAN class="string token">"Container"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">for</SPAN> dirname <SPAN class="keyword token">in</SPAN> dirnames<SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">if</SPAN> <SPAN class="string token">".gdb"</SPAN> <SPAN class="keyword token">in</SPAN> dirname<SPAN class="punctuation token">:</SPAN> env<SPAN class="punctuation token">.</SPAN>workspace <SPAN class="operator token">=</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN>dirpath<SPAN class="punctuation token">,</SPAN> dirname<SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># print env.workspace</SPAN> tableList <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>ListFeatureClasses<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># print tableList</SPAN> <SPAN class="keyword token">for</SPAN> table <SPAN class="keyword token">in</SPAN> tableList<SPAN class="punctuation token">:</SPAN> <SPAN class="comment token"># print</SPAN> <SPAN class="keyword token">print</SPAN> <SPAN class="string token">"{}\t{}\t{}"</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>dirpath<SPAN class="punctuation token">,</SPAN> dirname<SPAN class="punctuation token">,</SPAN> table<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>
Randy,
I have a similar issue I need help with if you don't mind. I have a few .xlsx files in a folder location (name example: Bermuda Rd MP 0_26 102017_TestTable.xlsx) and I would like to list the files and then split their names up to use as a query to update data in a ArcOnline feature service. The first part of the file name would be for the RoadName attribute (ex. Bermuda Rd) and the second part of the file name is the Milepost location (ex. 0_26) and the underscore in the file name would need to be replaced with a "." to match the ArcOnline Milepost attribute. How would I list the file names, split the text up and then use those as variables to build my query upon?
Thanks,
Anthony
with arcpy.walk there are a variety of other parameters that might be worth a read since they are specific to Arc* and do 'stuff' that the os equivalent can't do
Walk—Data Access module | ArcGIS Desktop
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.