<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: List Feature Classes within Subfolders using Python in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/list-feature-classes-within-subfolders-using/m-p/255993#M19691</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Awesome!&amp;nbsp; Thanks!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 07 Feb 2011 23:37:00 GMT</pubDate>
    <dc:creator>ChristinaHerrick1</dc:creator>
    <dc:date>2011-02-07T23:37:00Z</dc:date>
    <item>
      <title>List Feature Classes within Subfolders using Python</title>
      <link>https://community.esri.com/t5/python-questions/list-feature-classes-within-subfolders-using/m-p/255989#M19687</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'm trying to get a list of feature classes in a folder and it's subfolders.&amp;nbsp; Below is a script that gets just the folder specified.&amp;nbsp; Any help on how to loop through the subfolders is appreciated.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;import arcpy&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;from arcpy import env&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import os&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;# Set the workspace for the ListFeatureClass function&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;env.workspace = "C:/Data"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;# Use the ListFeatureClasses function to return a list&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;fcList = arcpy.ListFeatureClasses()&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;print fcList&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 06 Jan 2011 15:16:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/list-feature-classes-within-subfolders-using/m-p/255989#M19687</guid>
      <dc:creator>TomJansen</dc:creator>
      <dc:date>2011-01-06T15:16:53Z</dc:date>
    </item>
    <item>
      <title>Re: List Feature Classes within Subfolders using Python</title>
      <link>https://community.esri.com/t5/python-questions/list-feature-classes-within-subfolders-using/m-p/255990#M19688</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
import os

def fcs_in_workspace(workspace):
&amp;nbsp; arcpy.env.workspace = workspace
&amp;nbsp; for fc in arcpy.ListFeatureClasses():
&amp;nbsp;&amp;nbsp;&amp;nbsp; print os.path.join(workspace, fc)
&amp;nbsp; for ws in arcpy.ListWorkspaces():
&amp;nbsp;&amp;nbsp;&amp;nbsp; fcs_in_workspace(os.path.join(workspace, ws))

fcs_in_workspace("C:/Data")&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 12:37:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/list-feature-classes-within-subfolders-using/m-p/255990#M19688</guid>
      <dc:creator>JasonScheirer</dc:creator>
      <dc:date>2021-12-11T12:37:31Z</dc:date>
    </item>
    <item>
      <title>Re: List Feature Classes within Subfolders using Python</title>
      <link>https://community.esri.com/t5/python-questions/list-feature-classes-within-subfolders-using/m-p/255991#M19689</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;How would you then iterate through the list later in the script?&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Ex. "for fc in fclist: ..."&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 07 Feb 2011 20:58:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/list-feature-classes-within-subfolders-using/m-p/255991#M19689</guid>
      <dc:creator>ChristinaHerrick1</dc:creator>
      <dc:date>2011-02-07T20:58:02Z</dc:date>
    </item>
    <item>
      <title>Re: List Feature Classes within Subfolders using Python</title>
      <link>https://community.esri.com/t5/python-questions/list-feature-classes-within-subfolders-using/m-p/255992#M19690</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You could use a generator in this case:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
import os

def fcs_in_workspace(workspace):
&amp;nbsp; arcpy.env.workspace = workspace
&amp;nbsp; for fc in arcpy.ListFeatureClasses():
&amp;nbsp;&amp;nbsp;&amp;nbsp; yield os.path.join(workspace, fc)
&amp;nbsp; for ws in arcpy.ListWorkspaces():
&amp;nbsp;&amp;nbsp;&amp;nbsp; for fc in fcs_in_workspace(os.path.join(workspace, ws)):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; yield fc

for fc in fcs_in_workspace("C:/Data"):
&amp;nbsp;&amp;nbsp; ...
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Or you could do something like &lt;/SPAN&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;fclist = list(fcs_in_workspace("C:/Data"))&lt;/PRE&gt;&lt;SPAN&gt; and reuse it.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 12:37:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/list-feature-classes-within-subfolders-using/m-p/255992#M19690</guid>
      <dc:creator>JasonScheirer</dc:creator>
      <dc:date>2021-12-11T12:37:34Z</dc:date>
    </item>
    <item>
      <title>Re: List Feature Classes within Subfolders using Python</title>
      <link>https://community.esri.com/t5/python-questions/list-feature-classes-within-subfolders-using/m-p/255993#M19691</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Awesome!&amp;nbsp; Thanks!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 07 Feb 2011 23:37:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/list-feature-classes-within-subfolders-using/m-p/255993#M19691</guid>
      <dc:creator>ChristinaHerrick1</dc:creator>
      <dc:date>2011-02-07T23:37:00Z</dc:date>
    </item>
    <item>
      <title>Re: List Feature Classes within Subfolders using Python</title>
      <link>https://community.esri.com/t5/python-questions/list-feature-classes-within-subfolders-using/m-p/255994#M19692</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I wanted to add to additional ways to accomplish this and apply it to different data types.&lt;/P&gt;&lt;P&gt;I teach Python for Esri and have had this question come up in class alot.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;1. Arcpy.da.walk:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; This was introduced to the data access module at 10.1 SP1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;A href="http://resources.arcgis.com/en/help/main/10.2/#/Walk/018w00000023000000/" title="http://resources.arcgis.com/en/help/main/10.2/#/Walk/018w00000023000000/"&gt;ArcGIS Help (10.2, 10.2.1, and 10.2.2)&lt;/A&gt; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Where this function is nice is in 2 parameters&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Datatype: the value set here is the filter for what is returned as walk traverses the subfolders&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; type: not for all datasets, but at least you could specify point, line, poly or raster types&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Look at the Sample script 1 in the documentation &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;2. python os.walk:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; this function will perform the same type operation gathering subfolders and files&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; The one difference is this won't retrieve contents inside of a geodatabase.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; This could be used if you script involved python code with out the use of arcpy&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; maybe you needed to find all the .xls files under a D:\projects folder.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;A href="https://docs.python.org/2/library/os.html#os.walk" title="https://docs.python.org/2/library/os.html#os.walk"&gt;15.1. os — Miscellaneous operating system interfaces — Python 2.7.8 documentation&lt;/A&gt; &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Thanks, &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Jeff&lt;/STRONG&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 13 Nov 2014 21:34:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/list-feature-classes-within-subfolders-using/m-p/255994#M19692</guid>
      <dc:creator>JeffBigos</dc:creator>
      <dc:date>2014-11-13T21:34:03Z</dc:date>
    </item>
  </channel>
</rss>

