<?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: Script to loop through Multiple Datasets in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/script-to-loop-through-multiple-datasets/m-p/1145626#M63814</link>
    <description>&lt;P&gt;Use &lt;A href="https://pro.arcgis.com/en/pro-app/2.8/arcpy/data-access/walk.htm" target="_blank"&gt;Walk—ArcGIS Pro | Documentation&lt;/A&gt;, much more Pythonic than the older List functions.&amp;nbsp; The documentation has some working examples.&lt;/P&gt;</description>
    <pubDate>Fri, 18 Feb 2022 15:17:45 GMT</pubDate>
    <dc:creator>JoshuaBixby</dc:creator>
    <dc:date>2022-02-18T15:17:45Z</dc:date>
    <item>
      <title>Script to loop through Multiple Datasets</title>
      <link>https://community.esri.com/t5/python-questions/script-to-loop-through-multiple-datasets/m-p/1145424#M63808</link>
      <description>&lt;P&gt;Hi Everyone,&lt;/P&gt;&lt;P&gt;Is there a script where I can run through multiple datasets in a gdb.&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example: I want to add fields to every feature class&amp;nbsp; which is grouped in their respective datasets.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 17 Feb 2022 23:20:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/script-to-loop-through-multiple-datasets/m-p/1145424#M63808</guid>
      <dc:creator>SteveKim1</dc:creator>
      <dc:date>2022-02-17T23:20:32Z</dc:date>
    </item>
    <item>
      <title>Re: Script to loop through Multiple Datasets</title>
      <link>https://community.esri.com/t5/python-questions/script-to-loop-through-multiple-datasets/m-p/1145428#M63809</link>
      <description>&lt;P&gt;Yup, there is. See here&amp;nbsp;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/functions/listfeatureclasses.htm" target="_blank" rel="noopener"&gt;ListFeatureClasses—ArcGIS Pro | Documentation&lt;/A&gt;,&amp;nbsp;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/functions/listdatasets.htm" target="_blank" rel="noopener"&gt;ListDatasets—ArcGIS Pro | Documentation&lt;/A&gt;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;arcpy.env.workspace = [whatver your workspace is]
FClist = arcpy.ListFeatureClasses()
for FC in FClist:
    code
    code

#if using data sets
arcpy.env.workspace = [whatver your workspace is]

FDList = arcpy.ListDatasets()
for FD in FDList:
    FClist = arcpy.ListFeatureClasses()
    for FC in FClist:
        code
        code&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Feb 2022 23:34:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/script-to-loop-through-multiple-datasets/m-p/1145428#M63809</guid>
      <dc:creator>AlfredBaldenweck</dc:creator>
      <dc:date>2022-02-17T23:34:43Z</dc:date>
    </item>
    <item>
      <title>Re: Script to loop through Multiple Datasets</title>
      <link>https://community.esri.com/t5/python-questions/script-to-loop-through-multiple-datasets/m-p/1145626#M63814</link>
      <description>&lt;P&gt;Use &lt;A href="https://pro.arcgis.com/en/pro-app/2.8/arcpy/data-access/walk.htm" target="_blank"&gt;Walk—ArcGIS Pro | Documentation&lt;/A&gt;, much more Pythonic than the older List functions.&amp;nbsp; The documentation has some working examples.&lt;/P&gt;</description>
      <pubDate>Fri, 18 Feb 2022 15:17:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/script-to-loop-through-multiple-datasets/m-p/1145626#M63814</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2022-02-18T15:17:45Z</dc:date>
    </item>
    <item>
      <title>Re: Script to loop through Multiple Datasets</title>
      <link>https://community.esri.com/t5/python-questions/script-to-loop-through-multiple-datasets/m-p/1145644#M63815</link>
      <description>&lt;P&gt;Thanks Alfred for the script! When I use the second script to loop through the Datasets and then through each Feature Class, the ListFeatureClasses() function is not returning any values. Here's my script below:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SteveKim1_0-1645199794970.png" style="width: 675px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/34347iD79AD2B43302BE90/image-dimensions/675x199?v=v2" width="675" height="199" role="button" title="SteveKim1_0-1645199794970.png" alt="SteveKim1_0-1645199794970.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Did I miss any steps or anything wrong with this code?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Feb 2022 15:57:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/script-to-loop-through-multiple-datasets/m-p/1145644#M63815</guid>
      <dc:creator>SteveKim1</dc:creator>
      <dc:date>2022-02-18T15:57:50Z</dc:date>
    </item>
    <item>
      <title>Re: Script to loop through Multiple Datasets</title>
      <link>https://community.esri.com/t5/python-questions/script-to-loop-through-multiple-datasets/m-p/1145657#M63816</link>
      <description>&lt;P&gt;Oooh, I had no idea this existed. Thanks, I'll have to try this out!&lt;/P&gt;</description>
      <pubDate>Fri, 18 Feb 2022 16:23:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/script-to-loop-through-multiple-datasets/m-p/1145657#M63816</guid>
      <dc:creator>AlfredBaldenweck</dc:creator>
      <dc:date>2022-02-18T16:23:43Z</dc:date>
    </item>
    <item>
      <title>Re: Script to loop through Multiple Datasets</title>
      <link>https://community.esri.com/t5/python-questions/script-to-loop-through-multiple-datasets/m-p/1145686#M63818</link>
      <description>&lt;P&gt;Oops, it looks like I should have read the documentation more closely.&lt;/P&gt;&lt;P&gt;What happened was that ListFeatureClasses just grabs everything from the workspace, ignoring the stuff in datasets, unless you specify that you want the stuff in the datasets.&lt;/P&gt;&lt;P&gt;You may also want to try out Walk(), like Joshua suggested.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;arcpy.env.workspace =  r'=...\Data_Transfers.gdb'

field1 = "LATITURE" #These are mispelled
field2 ="LONGITURE"#These are mispelled

FDlist = arcpy.ListDatasets(feature_type='feature') #The parameter in here isn't strictly necessary
print(FDlist)
'''if you want to include all feature classes, regardless of wheteher they're in a dataset.'''
#FDlist = [''] + FDlist if FDlist is not None else [] 

for FD in FDlist:
    FClist= arcpy.ListFeatureClasses(feature_dataset = FD)
    for FC in FClist:
        print(FC)
        if not (field1 in arcpy.ListFields(FC) and (field2 in arcpy.ListFields(FC))):
            FC = arcpy.management.AddField(FC, field1, "DOUBLE",field_alias = "Lat")
            FC = arcpy.management.AddField(FC, field2, "DOUBLE",field_alias = "Long")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Feb 2022 17:26:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/script-to-loop-through-multiple-datasets/m-p/1145686#M63818</guid>
      <dc:creator>AlfredBaldenweck</dc:creator>
      <dc:date>2022-02-18T17:26:35Z</dc:date>
    </item>
  </channel>
</rss>

