I am using ArcGIS Pro 3.1.0.

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, but for optimization reasons I'd prefer to use arcpy.da.Walk. It looks like Walk doesn't detect feature datasets as feature datasets (it treats them as "folders").

import os
workspace=r'E:\GIS_DATA\ArcGIS\TestWalk' #TestWalk.gdb with 2 datasets is inside this folder
feature_datasets = []

walk = arcpy.da.Walk(workspace,datatype=["FeatureDataset"])

for dirpath, dirnames, filenames in walk:
    for filename in filenames:
        feature_datasets.append(os.path.join(dirpath, filename))
print ("Found:{0}".format(feature_datasets))

It doesn't find any datasets. Someone suggested to use dirnames:

for dirname in dirnames:
    feature_datasets.append(os.path.join(dirpath, dirname))

But then obviously also Window folders are returned.

Edit: There are quite a few possible workarounds. However for optimization reasons I'd like to stick to arcpy.da.Walk without any additional filtering (after all this is what datatype parameter should provide). So possible answer is that functionality of Arcpy.da.Walk is flawed and some workaround has to be used.

Edit 2: @user2856 answer has been accepted as it is probably the fastest workaround. If someone is confused as I was, please read his comment regarding specifics of arcpy.da.Walk. "Bug or Feature" is an open question.

  • 2
    Your second line of code is wrong. r'E:\GIS_DATA\ArcGIS\TestWalk' does not refer to #TestWalk.gdb (and is likely not present, hence the lack of results)
    – Vince
    Commented Jun 5, 2023 at 18:33
  • 1
    @Vince I read the code in question as stating that the TestWalk.gdb is inside the TestWalk folder. If so arcpy.da.Walk will find it.
    – user2856
    Commented Jun 5, 2023 at 21:32
  • @user2856 You're right. I didn't forget to include TestWalk.gdb there :)
    – Szym
    Commented Jun 6, 2023 at 6:42
  • Cross post : community.esri.com/t5/python-questions/…
    – Szym
    Commented Jun 6, 2023 at 7:17

1 Answer 1


The suggestion to use directory names is technically correct.

arcpy.da.Walk considers a feature dataset to be a container (like a directory or a toolbox), and includes that in the 2nd output dirnames:

dirnames is a list of names of subdirectories and other workspaces in dirpath.

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.

Perhaps including subdirectories is a bug or perhaps it's intended.

Either way, you are not going to get a list of feature datasets in Walk's 3rd output filenames:

filenames is a list of names of nonworkspace contents in dirpath.

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:

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))



['D:\\Temp\\test\\test.gdb\\test_fd1', 'D:\\Temp\\test\\test.gdb\\test_fd2']
  • I don't fully agree that suggestion to use directory names is correct. In my case feature dataset is "final search product". Esri theoretically enables to filter out by feature dataset in datatype parameter. Please note that your current code will include other "directory" features (eg toolbox) if it is inside GDB. Of course we could test if found directory is feature dataset - but then I would expect that datatype parameter of arcpy.da.Walk should handle it. So basically my question could be narrowed to : is there any way to make datatype parameter work properly with feature dataset?
    – Szym
    Commented Jun 6, 2023 at 6:59
  • 1
    "Please note that your current code will include other "directory" features (eg toolbox) if it is inside GDB.". No, that's incorrect. It will only include feature datasets, because I specified datatype="FeatureDataset". If I leave that out, then it will include toolboxes, etc.
    – user2856
    Commented Jun 6, 2023 at 7:26
  • "No, that's incorrect". Yes, my mistake. And I fully agree with your last comment.
    – Szym
    Commented Jun 6, 2023 at 7:47
  • So I'd make minor correction to your code os.path.splitext(root)[-1].lower() - to prevent uppercase GDB being omitted. Being slave to the details: code could be technically broken by creating fake.gdb windows folder and putting subfolders there, but it isn't very likely :) Not worth of putting arcpy.Describe datatype check anyway. Thanks for your time and detailed explanations.
    – Szym
    Commented Jun 6, 2023 at 8:29
  • Code and answer updated to reflect comments.
    – user2856
    Commented Jun 6, 2023 at 9:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.