AnsweredAssumed Answered

Delete Empty Datasets

Question asked by sarojthapa60 on Jun 5, 2018
Latest reply on Jun 11, 2018 by sarojthapa60

I am working on creating a script/tool that deletes empty feature classes that reside inside feature datasets. Some datasets have empty feature classes. When those empty feature classes are deleted, some datasets become empty. I could not figure out how to count the number of datasets in a file gdb and delete them if they are empty.

 

 

import arcpy
import os
arcpy.env.workspace = r"C:\Users\s\Documents\ArcGIS\Default.gdb"
#arcpy.env.workspace = arcpy.GetParameterAsText(0)
#listFCs = arcpy.ListFeatureClasses()
listDSs = arcpy.ListDatasets("*", "All")
# Delete empty Feature Classes inside Feature Dataset
for ds in listDSs:
for fc in arcpy.ListFeatureClasses(feature_dataset=ds):
count = str(arcpy.GetCount_management(fc))
if count == "0":
arcpy.Delete_management(fc)
# Delete empty Feature Datasets
# First count number of feature datasets and check if they are empty
for ds2 in listDSs:
print (ds2)
print "Script Completed!"

 I used similar approach to fc in ds, but got the following errors:

 

ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000840: The value is not a Table View.
ERROR 000840: The value is not a Raster Layer.
Failed to execute (GetCount).

 

Please help.

Thanks,

Outcomes