I posted a similar question before, but I am trying to list all of the element types in the geodatabase, such as feature datasets, networks, rasters, domains, non-spatial tables, etc.

For rasters, I got the following code working.

#Get Raster datasets
rasters = arcpy.ListRasters()

for rs in rasters:

However, I was told that I should probably use Walk function instead of ListFeature function. The following is the the sample code I found, but was unable to find a way to print the result.

What change do I need to make to the following code to make it print results?

workspace = "c:/data"
rasters = []

walk = arcpy.da.Walk(workspace, topdown=True, datatype="RasterDataset")

for dirpath, dirnames, filenames in walk:
    # Disregard any folder named 'back_up' in creating list of rasters
    if "back_up" in dirnames:
    for filename in filenames:
        rasters.append(os.path.join(dirpath, filename))
  • 2
    Are you looking for something other than print(rasters)?
    – Aaron
    Feb 10 '20 at 22:04
  • 1
    Oh I just found out I can simply use arcpy.Addmessage to print my result on ArcGIS. I cannot believe how dumb I am,but thank you so much!
    – Yoshi
    Feb 10 '20 at 22:22

To address your broader question, you could create a report based on the information in arcpy.da.Describe (ArcGIS Pro only I think, but you can use the older arcpy.Describe object in ArcMap, though the syntax is different).

In the example below, I use walk to find everything (not looking just for rasters or feature classes), then use arcpy.da.Describe to get detailed info about each element including datatype, then use a dictionary to group by datatype:

import os
from collections import defaultdict 

def domain_report(gdb):
    domains = arcpy.da.ListDomains(gdb)
    report = []
    if bool(domains):
        report += ["Domain:"]

    for domain in domains:
        report += [f'\t\t{domain.name}: {domain.domainType}']
        if domain.domainType == 'CodedValue':
            coded_values = domain.codedValues
            for val, desc in coded_values.items():
                report += [f'\t\t\t\t{val}: {desc}']
        elif domain.domainType == 'Range':
            report += [f'\t\t\t\t{domain.range[0]} - {domain.range[1]}']

    return report

def data_report(gdb):

    elements = defaultdict(list)

    walk = arcpy.da.Walk(gdb, topdown=True)

    for dirpath, dirnames, filenames in walk:
        for dirname in dirnames:  # 'FeatureDataset'
            desc = arcpy.da.Describe(os.path.join(dirpath, dirname))

        for filename in filenames:
            desc = arcpy.da.Describe(os.path.join(dirpath, filename))

    report = []

    for element_type, element_list in elements.items():
        report += [f"{element_type}:"]
        for element_description in element_list:
            report +=  [f"\t\t{element_description['catalogPath']}"] # Here I just output the path, but there's lots more info in the Describe object

    return report

gdb = r"D:\Temp\SampleData.gdb"

report = domain_report(gdb) + data_report(gdb)

Example output:

        dAccessControl: CodedValue
                1: Full Access Control
                2: Partial Access Control
                3: No Access Control
  • Wow, this looks like what I need for my next step!. When you said "I use walk to find everything (not looking just for rasters or feature classes)," what do you mean by everything? Does that include all of the element types in the geodatabase, such as feature datasets, networks, rasters, domains, non-spatial tables, etc?
    – Yoshi
    Feb 12 '20 at 20:49
  • @Yoshi Walk doesn't report domains, see edit.
    – user2856
    Feb 12 '20 at 23:09
import arcpy
import os

#Set a workspace 
workspace = arcpy.GetParameterAsText(0)

#Get Featureclasse
walk = arcpy.da.Walk(workspace, datatype="FeatureClass")

for dirpath, dirnames, filenames in walk:
    for filename in filenames:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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