<?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: Getting feature datasets with arcpy.da.Walk (ArcGIS Pro 3.1.0) in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/getting-feature-datasets-with-arcpy-da-walk-arcgis/m-p/1295852#M67806</link>
    <description>&lt;P&gt;Did you check your code with datasets? Did it return only datasets? In my case it returns all windows folders + datasets inside GDB.&lt;/P&gt;&lt;P&gt;Modified code as suggested by JeffK:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import os

workspace=r'E:\GIS_DATA\ArcGIS\TestWalk'

feature_datasets = []

walk = arcpy.da.Walk(workspace,datatype=["FeatureDataset"])

for dirpath, dirnames, filenames in walk:
    for dirname in dirnames:
        feature_datasets.append(os.path.join(dirpath, dirname))
print ("Found:{0}".format(feature_datasets))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Result:&lt;/P&gt;&lt;PRE&gt;Found:['E:\\GIS_DATA\\ArcGIS\\TestWalk\\Index', 'E:\\GIS_DATA\\ArcGIS\\TestWalk\\TestWalk.gdb', 'E:\\GIS_DATA\\ArcGIS\\TestWalk\\ImportLog', 'E:\\GIS_DATA\\ArcGIS\\TestWalk\\GpMessages', 'E:\\GIS_DATA\\ArcGIS\\TestWalk\\.ipynb_checkpoints', 'E:\\GIS_DATA\\ArcGIS\\TestWalk\\.backups', 'E:\\GIS_DATA\\ArcGIS\\TestWalk\\Temp', 'E:\\GIS_DATA\\ArcGIS\\TestWalk\\Index\\TestWalk', 'E:\\GIS_DATA\\ArcGIS\\TestWalk\\Index\\Thumbnail', 'E:\\GIS_DATA\\ArcGIS\\TestWalk\\TestWalk.gdb\\DS1', 'E:\\GIS_DATA\\ArcGIS\\TestWalk\\TestWalk.gdb\\DS2']&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 05 Jun 2023 16:02:54 GMT</pubDate>
    <dc:creator>SzymAdamowski</dc:creator>
    <dc:date>2023-06-05T16:02:54Z</dc:date>
    <item>
      <title>Getting feature datasets with arcpy.da.Walk (ArcGIS Pro 3.1.0)</title>
      <link>https://community.esri.com/t5/python-questions/getting-feature-datasets-with-arcpy-da-walk-arcgis/m-p/1295643#M67785</link>
      <description>&lt;P&gt;I'm trying to find feature datasets in file geodatabase (possibly many geodatabases, but for clarity here only one) using arcpy.da.Walk. I'm aware of workaround using ListDatasets and I'm aware of similiar topic (&lt;A href="https://community.esri.com/t5/python-questions/arcpy-da-walk-workspace-datatype-quot/m-p/595010" target="_blank" rel="noopener"&gt;https://community.esri.com/t5/python-questions/arcpy-da-walk-workspace-datatype-quot/m-p/595010&lt;/A&gt;), but this one is from 2015. We have 2023, ArcGIS Pro 3.1 and it looks like it is still the same - arcpy.da.Walk doesn't detect feature datasets as feature datasets (it treats them as "folders")- or am I doing something wrong?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import os
workspace=r'E:\GIS_DATA\ArcGIS\TestWalk\TestWalk.gdb'
feature_datasets = []

walk = arcpy.da.Walk(workspace,datatype=["FeatureDataset"])

for dirpath, dirnames, filenames in walk:
    print (dirpath,dirnames,filenames)
    for filename in filenames:
        feature_datasets.append(os.path.join(dirpath, filename))
print ("Found:{0}".format(feature_datasets))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is my geodatabase structue:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SzymAdamowski_0-1685898703834.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/72316i3059E91418637934/image-size/medium?v=v2&amp;amp;px=400" role="button" title="SzymAdamowski_0-1685898703834.png" alt="SzymAdamowski_0-1685898703834.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;This is the result of the script:&lt;/P&gt;&lt;PRE&gt;E:\GIS_DATA\ArcGIS\TestWalk\TestWalk.gdb ['DS1', 'DS2'] []
E:\GIS_DATA\ArcGIS\TestWalk\TestWalk.gdb\DS1 [] []
E:\GIS_DATA\ArcGIS\TestWalk\TestWalk.gdb\DS2 [] []
Found:[]&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 04 Jun 2023 17:18:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/getting-feature-datasets-with-arcpy-da-walk-arcgis/m-p/1295643#M67785</guid>
      <dc:creator>SzymAdamowski</dc:creator>
      <dc:date>2023-06-04T17:18:57Z</dc:date>
    </item>
    <item>
      <title>Re: Getting feature datasets with arcpy.da.Walk (ArcGIS Pro 3.1.0)</title>
      <link>https://community.esri.com/t5/python-questions/getting-feature-datasets-with-arcpy-da-walk-arcgis/m-p/1295763#M67789</link>
      <description>&lt;P&gt;Your code is looking for filenames instead of the dataset (directory).&amp;nbsp; Since there are no files in there, the filenames will be empty [].&amp;nbsp; If you want it to list the datasets, you should iterate over the dirnames.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;    for dirname in dirnames:
        feature_datasets.append(os.path.join(dirpath, dirname))

print ("Found:{0}".format(feature_datasets))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Jun 2023 12:51:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/getting-feature-datasets-with-arcpy-da-walk-arcgis/m-p/1295763#M67789</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2023-06-05T12:51:50Z</dc:date>
    </item>
    <item>
      <title>Re: Getting feature datasets with arcpy.da.Walk (ArcGIS Pro 3.1.0)</title>
      <link>https://community.esri.com/t5/python-questions/getting-feature-datasets-with-arcpy-da-walk-arcgis/m-p/1295852#M67806</link>
      <description>&lt;P&gt;Did you check your code with datasets? Did it return only datasets? In my case it returns all windows folders + datasets inside GDB.&lt;/P&gt;&lt;P&gt;Modified code as suggested by JeffK:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import os

workspace=r'E:\GIS_DATA\ArcGIS\TestWalk'

feature_datasets = []

walk = arcpy.da.Walk(workspace,datatype=["FeatureDataset"])

for dirpath, dirnames, filenames in walk:
    for dirname in dirnames:
        feature_datasets.append(os.path.join(dirpath, dirname))
print ("Found:{0}".format(feature_datasets))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Result:&lt;/P&gt;&lt;PRE&gt;Found:['E:\\GIS_DATA\\ArcGIS\\TestWalk\\Index', 'E:\\GIS_DATA\\ArcGIS\\TestWalk\\TestWalk.gdb', 'E:\\GIS_DATA\\ArcGIS\\TestWalk\\ImportLog', 'E:\\GIS_DATA\\ArcGIS\\TestWalk\\GpMessages', 'E:\\GIS_DATA\\ArcGIS\\TestWalk\\.ipynb_checkpoints', 'E:\\GIS_DATA\\ArcGIS\\TestWalk\\.backups', 'E:\\GIS_DATA\\ArcGIS\\TestWalk\\Temp', 'E:\\GIS_DATA\\ArcGIS\\TestWalk\\Index\\TestWalk', 'E:\\GIS_DATA\\ArcGIS\\TestWalk\\Index\\Thumbnail', 'E:\\GIS_DATA\\ArcGIS\\TestWalk\\TestWalk.gdb\\DS1', 'E:\\GIS_DATA\\ArcGIS\\TestWalk\\TestWalk.gdb\\DS2']&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Jun 2023 16:02:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/getting-feature-datasets-with-arcpy-da-walk-arcgis/m-p/1295852#M67806</guid>
      <dc:creator>SzymAdamowski</dc:creator>
      <dc:date>2023-06-05T16:02:54Z</dc:date>
    </item>
    <item>
      <title>Re: Getting feature datasets with arcpy.da.Walk (ArcGIS Pro 3.1.0)</title>
      <link>https://community.esri.com/t5/python-questions/getting-feature-datasets-with-arcpy-da-walk-arcgis/m-p/1296202#M67819</link>
      <description>&lt;P&gt;From cross-posted Gis Stack Exchange (&lt;A href="https://gis.stackexchange.com/questions/461082/getting-feature-datasets-with-arcpy-da-walk" target="_blank" rel="noopener"&gt;https://gis.stackexchange.com/questions/461082/getting-feature-datasets-with-arcpy-da-walk&lt;/A&gt;), using explanations by user2856 who greatly contribued to finding issues with my approach:&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080"&gt;The suggestion to use directory names is technically correct.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080"&gt;arcpy.da.Walk considers a feature dataset to be a container (like a directory or a toolbox), and includes that in the &lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/data-access/walk.htm" target="_blank" rel="nofollow noopener noreferrer"&gt;2nd output&lt;/A&gt; dirnames:&lt;/FONT&gt;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;&lt;FONT color="#000080"&gt;dirnames is a list of names of subdirectories &lt;STRONG&gt;and other workspaces&lt;/STRONG&gt; in dirpath.&lt;/FONT&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;FONT color="#000080"&gt;These other workspaces can include feature datasets and toolboxes inside a geodatabase. When you restrict by specifying datatype="FeatureDataset" you get a list of subdirectories and feature datasets.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080"&gt;Perhaps including subdirectories is a bug or perhaps it's intended.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080"&gt;Either way, you are not going to get a list of feature datasets in Walk's 3rd output filenames:&lt;/FONT&gt;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;&lt;FONT color="#000080"&gt;filenames is a list of names of &lt;STRONG&gt;nonworkspace&lt;/STRONG&gt; contents in dirpath.&lt;/FONT&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;FONT color="#000080"&gt;However, you will need to either test all directories to see if they're feature datasets (slow) or simply check if the parent is a file GDB or enterprise GDB connection:&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;workspace=r'D:\Temp\test' #test.gdb with 2 datasets is inside this folder
feature_datasets = []

for root, dirs, files in arcpy.da.Walk(workspace, datatype="FeatureDataset"):
    if os.path.splitext(root.lower())[-1] in (".gdb", ".sde"):
        for dirname in dirs:
            feature_datasets.append(os.path.join(root, dirname))

print(feature_datasets)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1. Code and explanation in blue which are from StackExchange user2856 are probably the best (fastest and elegant) approach that currently could be applied with arcpy.da.Walk. However: it should be noted that strictly speaking Feature Dataset is not Workspace (at least not in arcpy.Describe terms). In a perferct world arcpy.da.Walk could be rewritten in such a way that:&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080"&gt;filenames is a list of names of &lt;STRONG&gt;nonworkspace&lt;/STRONG&gt; contents&amp;nbsp;in dirpath &lt;STRONG&gt;and workspaces if&amp;nbsp; they're defined in datatype parameter &lt;/STRONG&gt;in dirpath.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;That would enable easy data harvesting without use of additional conditions&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;2. Trying to understand logic behing treating Feature Datasets as Workspaces (ok, I get it, it is a "container" holding nested data, so in this meaning it is a Workspace), I added Toolbox in Geodatabase. I was expecting similiar behaviour (after all it is a container holding tools), so I tested following code:&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import os
workspace=r'E:\GIS_DATA\ArcGIS\TestWalk' #Contains TestWalk.gdb that contains 2 datasets and 1 toolbox


feature_datasets = []

walk = arcpy.da.Walk(workspace,datatype=["Toolbox"])

for dirpath, dirnames, filenames in walk:
    if os.path.splitext(dirpath.lower())[-1] in (".gdb", ".sde"):
        print (dirpath,dirnames,filenames)
        for dirname in dirnames:
            feature_datasets.append(os.path.join(dirpath, dirname))
print ("Found:{0}".format(feature_datasets))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To my surprise this code finds &lt;STRONG&gt;Feature Datasets&lt;/STRONG&gt; instead of &lt;STRONG&gt;Toolbox&lt;/STRONG&gt;:&lt;/P&gt;&lt;PRE&gt;E:\GIS_DATA\ArcGIS\TestWalk\TestWalk.gdb ['DS1', 'DS2'] []
Found:['E:\\GIS_DATA\\ArcGIS\\TestWalk\\TestWalk.gdb\\DS1', 'E:\\GIS_DATA\\ArcGIS\\TestWalk\\TestWalk.gdb\\DS2']&lt;/PRE&gt;&lt;P&gt;&lt;STRONG&gt;That looks like obvious bug.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Conclusion: &lt;/STRONG&gt;It woud be great if Esri developers could have a look at arcpy.da.Walk and :&lt;/P&gt;&lt;P&gt;a) corrected bugs (eg. datatype="Toolbox" working incorrectly with toolboxes in Geodatabase and some other found in other topics)&lt;/P&gt;&lt;P&gt;b) possibly redesigned to make it use more intuitive (i.e. Feature Datasets could be included aslo in &lt;STRONG&gt;filenames&lt;/STRONG&gt; and not only in &lt;STRONG&gt;dirnames&lt;/STRONG&gt; if they're specified in &lt;STRONG&gt;datatype&lt;/STRONG&gt; parameter) or at least improved documentation so that it would be clear which datatypes are returned in &lt;STRONG&gt;dirnames&lt;/STRONG&gt; and which are returned in &lt;STRONG&gt;filenames&lt;/STRONG&gt;.&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Tue, 06 Jun 2023 13:12:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/getting-feature-datasets-with-arcpy-da-walk-arcgis/m-p/1296202#M67819</guid>
      <dc:creator>SzymAdamowski</dc:creator>
      <dc:date>2023-06-06T13:12:57Z</dc:date>
    </item>
    <item>
      <title>Re: Getting feature datasets with arcpy.da.Walk (ArcGIS Pro 3.1.0)</title>
      <link>https://community.esri.com/t5/python-questions/getting-feature-datasets-with-arcpy-da-walk-arcgis/m-p/1297568#M67893</link>
      <description>&lt;P&gt;Yes I did, and I only had a dataset in the gdb and nothing else. Point was it should be dirnames and not filenames that you were iterating over and glad you found a workable solution. Walk doesn't seem all together quite yet does it?&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2023 13:12:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/getting-feature-datasets-with-arcpy-da-walk-arcgis/m-p/1297568#M67893</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2023-06-09T13:12:04Z</dc:date>
    </item>
    <item>
      <title>Re: Getting feature datasets with arcpy.da.Walk (ArcGIS Pro 3.1.0)</title>
      <link>https://community.esri.com/t5/python-questions/getting-feature-datasets-with-arcpy-da-walk-arcgis/m-p/1297571#M67894</link>
      <description>&lt;P&gt;To discriminate between feature datasets and windows folders,&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;if arcpy.Describe(dirname).dataType == "FeatureDataset":&lt;/PRE&gt;</description>
      <pubDate>Fri, 09 Jun 2023 13:16:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/getting-feature-datasets-with-arcpy-da-walk-arcgis/m-p/1297571#M67894</guid>
      <dc:creator>AlfredBaldenweck</dc:creator>
      <dc:date>2023-06-09T13:16:36Z</dc:date>
    </item>
    <item>
      <title>Re: Getting feature datasets with arcpy.da.Walk (ArcGIS Pro 3.1.0)</title>
      <link>https://community.esri.com/t5/python-questions/getting-feature-datasets-with-arcpy-da-walk-arcgis/m-p/1297596#M67916</link>
      <description>&lt;P&gt;So in your case it returned only Datasets even when you started Walk from Windows Folder workspace that contains different folders?&amp;nbsp; In my case&amp;nbsp; it includes Windows folders, GDBs and (last but not least) Datasets.&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2023 14:27:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/getting-feature-datasets-with-arcpy-da-walk-arcgis/m-p/1297596#M67916</guid>
      <dc:creator>SzymAdamowski</dc:creator>
      <dc:date>2023-06-09T14:27:28Z</dc:date>
    </item>
    <item>
      <title>Re: Getting feature datasets with arcpy.da.Walk (ArcGIS Pro 3.1.0)</title>
      <link>https://community.esri.com/t5/python-questions/getting-feature-datasets-with-arcpy-da-walk-arcgis/m-p/1297597#M67917</link>
      <description>&lt;P&gt;That will work as well and code looks simpler, however line&lt;/P&gt;&lt;PRE&gt;if os.path.splitext(dirpath.lower())[-1] in (".gdb", ".sde")&lt;/PRE&gt;&lt;P&gt;is slightly more efficient as it will check data at higher level (parent folder rather then all child folders)&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2023 14:30:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/getting-feature-datasets-with-arcpy-da-walk-arcgis/m-p/1297597#M67917</guid>
      <dc:creator>SzymAdamowski</dc:creator>
      <dc:date>2023-06-09T14:30:31Z</dc:date>
    </item>
    <item>
      <title>Re: Getting feature datasets with arcpy.da.Walk (ArcGIS Pro 3.1.0)</title>
      <link>https://community.esri.com/t5/python-questions/getting-feature-datasets-with-arcpy-da-walk-arcgis/m-p/1297602#M67918</link>
      <description>&lt;P&gt;No, I pointed Walk directly at the gdb because that is where FeatureDatasets are found and is easier to test/ demonstrate the dirname filename issue.&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2023 14:45:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/getting-feature-datasets-with-arcpy-da-walk-arcgis/m-p/1297602#M67918</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2023-06-09T14:45:17Z</dc:date>
    </item>
  </channel>
</rss>

