1

Are there any alternatives to the arcpy list functions (ListDatasets, etc.) where the directory can be specified rather than using the env.workspace?

For example, what if I would like to get a list of datasets in several different directories?

Or if I have my workspace in_memory?

The os.walk might partially work, but won't recognize non-file-based data types. Is another function or snippets that can accomplish this?

1
  • I disagree that the question is duplicate although they share an answer. If one asked who was the 2nd president of the US, would that be a duplicate to the question of who was the 1st vice president? (John Adams)
    – Rex
    Commented Jun 2, 2017 at 13:27

1 Answer 1

4

The function that I think may work for you is arcpy.da.Walk()

This works in a similar way to os.walk() but can walk through geodatabases as well as folders, and recognises spatial data types, tables, feature classes as well as files.

Code sample from the Walk documentation:

import arcpy
import os

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

walk = arcpy.da.Walk(workspace, datatype="FeatureClass", type="Polygon")

for dirpath, dirnames, filenames in walk:
    for filename in filenames:
        feature_classes.append(os.path.join(dirpath, filename))

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