[GIS] Searching Geodatabase for Feature Class or Table by its name

arcgis-10.1arcgis-desktoparcpyesri-geodatabasesearch window

I'm looking for a way to search Geodatabases for a Feature Class or Table by using its name.

Is there any function like this available?

Obviously windows search only returns the random ID's for the tables within a Geodatabase. I'd like to actually search for datasets within them.

I think this would help a lot of people, because I know I'm not the only one out there who stores spatial data in Geodatabases, only to archive it with a thousand other datasets and not want to sift through it.

I'd like to search these Geodatabases within ArcCatalog.

Best Answer

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.