Skip to main content

ListDatasets

Summary

Returns a list of datasets in the current workspace. Search conditions can be specified for the dataset name and dataset type to limit the list that is returned.

Discussion

The workspace environment must be set before using several of the list functions, including ListDatasets, ListFeatureClasses, ListFiles, ListRasters, ListTables, and ListWorkspaces.

Syntax

ListDatasets({wild_card}, {feature_type})

Parameter Explanation Data Type

wild_card

Limits the results returned. If a value is not specified, all values are returned. The wildcard is not case sensitive.

Use an asterisk (*) to represent zero or more characters. For example, Te* finds Tennessee and Texas.

String

feature_type

Specifies the type of dataset that will be returned.

  • Coverage—Coverages will be returned.

  • Feature—Coverages or geodatabase datasets will be returned, depending on the workspace.

  • GeometricNetwork—Geometric network datasets will be returned.

  • LasDataset—LAS datasets will be returned.

  • Mosaic—Mosaic datasets will be returned.

  • Network—Network datasets will be returned.

  • ParcelFabric—Parcel fabric datasets will be returned.

  • ParcelFabricForArcmap—ArcMap parcel fabric datasets will be returned.

  • Raster—Raster datasets will be returned.

  • RasterCatalog—Raster catalog datasets will be returned.

  • Terrain—Terrain datasets will be returned.

  • Tin—TIN datasets will be returned.

  • Topology—Topology datasets will be returned.

  • TraceNetwork—Trace network datasets will be returned.

  • UtilityNetwork—Utility network datasets will be returned.

  • All—All datasets in the workspace will be returned. This is the default.

String

Return value

Data Type Explanation

String

A list containing dataset names returned from the function, limited by the wildcard and feature type arguments.

Code sample

ListDatasets example

List feature dataset names that start with C.

import arcpy

arcpy.env.workspace = "c:/data"

# Print all the feature datasets in the workspace that start with the letter C.
datasets = arcpy.ListDatasets("C*", "Feature")

for dataset in datasets:
    print(dataset)
ListDatasets example 2

List feature dataset names that start with c or f, start with letters except c, or contain both c and f.

import arcpy
arcpy.env.workspace = 'c:/data'

# Print all the feature datasets in the workspace that start with the letter c
# or f.
datasets1 = list(set(arcpy.ListDatasets("c*", "Feature")) |
                 set(arcpy.ListDatasets("f*", "Feature")))
print(datasets1)

# Print all the feature datasets in the workspace that start with the letters
# except c.
datasets2 = list(set(arcpy.ListDatasets("*", "Feature")) -
                 set(arcpy.ListDatasets("c*", "Feature")))
print(datasets2)

# Print all the feature datasets in the workspace that contain both the letter c
# and f.
datasets3 = list(set(arcpy.ListDatasets("*c*", "Feature")) &
                 set(arcpy.ListDatasets("*f*", "Feature")))
print(datasets3)
ListDatasets example 3

List trace network datasets using the feature_type keyword argument.

import arcpy

arcpy.env.workspace = 'c:/data/myGDB.gdb/TN_dataset'

# Print all the trace networks in the workspace.
datasets = arcpy.ListDatasets(feature_type="tracenetwork")
for dataset in datasets:
    print(dataset)
ListDatasets example 4

List raster datasets in a geodatabase using positional arguments.

import arcpy

arcpy.env.workspace = 'c:/data/mySQLserver.sde'

# Print all the raster datasets in the workspace.
datasets = arcpy.ListDatasets("", "Raster")
for dataset in datasets:
    print(dataset)
ListDatasets example 5

List feature datasets in an enterprise geodatabase that are owned by a specific user.

import arcpy
arcpy.env.workspace = 'c:/data/mySQLserver.sde'

# Print all the feature datasets owned by 'user1' in the enterprise gdb
datasets = arcpy.ListDatasets("user1*", "Feature")
for dataset in datasets:
    print(dataset)