Searching Geodatabase for Feature Class or Table by its name?

Another way to search for feature classes, which may or may not be in a dataset is to use the walk function, as mentioned before. It requires only a workspace to search in (i.e. a folder containing hundreds of GDBs).

import arcpy, os
workspace = "Path/to/folder"
search = "name_string_you_are_searching_for"
feature_classes = []
for dirpath, dirnames, filenames in arcpy.da.Walk(workspace,
                                                  datatype="FeatureClass",
                                                  type="ANY"):
    for fname in filenames:
        # search for string in string to eliminate the need for exact filenames
        if search.upper() in fname.upper():
            feature_classes.append(os.path.join(dirpath, fname))

The resulting list will contain the paths and filenames of all feature classes that match your search criteria, which can be printed.

for fc in feature_classes:
     print fc

The walk function can also be modified to search for specific types of features (i.e. polygons, points, rasters, etc) by changing type="" to the feature type.


This is a long way of doing what you're asking, using some python:

  1. You need a list of all the GeoDatabases that you want to search. If there are a lot, use python's walk function on the directory in question. Isolate for any folders with a .gdb in them or .mdb, depending on the database.

  2. Find all the datasets within the GeoDatabase.

  3. Find all the layers within the dataset.

  4. Search results from layers for what you are looking for.

Here is a code sample of what I'm talking about:

import arcpy
from arcpy import env
x = 'File Name That You Are Looking For'
GDBs = ['GeoDatabase1', 'GeoDatabase2', 'ect']  # Your list of GeoDatabases
for GDB in GDBs:                                # Iterate through your list
    env.workspace = GDB
    GDBds = arcpy.ListDatasets()                # Find datasets in GeoDatabase
    for ds in GDBds:                            # Iterate through datasets
        env.workspace = GDB + '/' + ds
        fc = arcpy.ListFeatureClasses()         # Find all data in the dataset
        for f in fc:
            if f.find(x) != -1:
                print GDB + '/' + ds + '/' + f