Is there a tool or script in ArcMap (currently using 10.5.1 basic) to identify empty feature classes without deleting them? I have to keep all feature classes in the geodatabase, even if they are empty, but I would like to know which ones actually have data without going through every feature class. There are up to 522 feature classes per geodatabase, with 100+ databases.
2 Answers
You can run the code below in the Python window within ArcMap. You will first have to copy the path to the directory containing all of your geodatabases and insert it into the script at the identified location. That is, replace "path\Goes\Here" with your path.
import os, arcpy
# Copy the path to the directory containing your geodatabases and insert path
# in between the single quotes below, like "GDBs = r'D:\GIS Data\GDBs'"
GDBs = r'path\Goes\Here'
L = []
GDBList = []
for paths, directories, files in os.walk(GDBs):
for dir in directories:
L.append(os.path.join(paths, dir))
for i in L:
if i.endswith('.gdb'):
GDBList.append(i)
print GDBList
for GDB in GDBList:
arcpy.env.workspace = GDB
datasets = arcpy.ListDatasets()
FCs = []
for fc in arcpy.ListFeatureClasses():
result = arcpy.GetCount_management(fc)
print str(GDB) + ',' + str(fc) + ',' + str(result)
for ds in datasets:
for fc in arcpy.ListFeatureClasses(feature_dataset=ds):
result = arcpy.GetCount_management(fc)
print str(GDB) + ',' + str(fc) + ',' + str(result)
This will create a comma separated list containing the geodatabase name, the feature class name, and number of features within the feature classes. This list can be copied from the Python window within ArcMap and pasted into a spreadsheet. This will not alter the data within the geodatabases in any way.
You can use GetCount_management to identify whether there are any feature classes with zero records.
Example usage:
# 1. Look for geodatabases in your environment to loop through
# http://pro.arcgis.com/en/pro-app/arcpy/functions/listworkspaces.htm
# 2. Loop through the geodatabases and identify feature classes
# http://pro.arcgis.com/en/pro-app/arcpy/functions/listworkspaces.htm
# (Note: may need to handle feature classes within feature datasets)
# http://pro.arcgis.com/en/pro-app/arcpy/functions/listdatasets.htm
# 3. Identify the empty feature classes
for fc in fcs:
numRows = int(arcpy.GetCount_management(fc).getOutput(0))
# http://pro.arcgis.com/en/pro-app/tool-reference/data-management/get-count.htm
if numRows == 0:
print('{} has {} records'.format(fc, numRows))
SELECT * ... LIMIT 1
queries via ArcSDESQLExecute, though file geodatabases would likely require arcpy'sGetCount_management()
. Please Edit the question to contain your code if you have difficulty.