http://pro.arcgis.com/en/pro-app/arcpy/functions/listfeatureclasses.htm
arcpy.env.workspace = <workspace>
fcs = arcpy.ListFeatureClasses('*')
for fc in fcs:
test = int(arcpy.GetCount_management(fc).getOutput(0))
print 'Feature Count: {}'.format(test)
if test > 0:
print 'Deleting Feature Class: {}'.format(fc)
arcpy.Delete_management(fc)
To add onto the concepts covered by @James, the following will take an input directory and loop over the gdbs and FCs for each one.
import arcpy
import os
inputDir = r'path\to\directory\that\houses\geodatabases'
ext = ['.mdb','.gdb']
gdbs = [x for x in os.listdir(inputDir) if x[-4:] in ext]
for g in gdbs:
fullpath = os.path.join(inputDir, g)
arcpy.env.workspace = fullpath
for fc in arcpy.ListFeatureClasses():
rowCount = arcpy.GetCount_management(fc)[0]
if rowCount == '0':
print "Deleting empty FC: {0}".format(os.path.join(g,fc))
arcpy.Delete_management(os.path.join(fullpath,fc))
else:
print "{0} contains {1} records".format(os.path.join(g,fc), rowCount)
Hi Dear,
attached below snapshot can you give the solution for attached image.Delete multiple mdb empty feature class one time all mdb.
Thanks
Santhosh
You are using filename in the listing of extensions. Just use the extension:
ext = ['.mdb','.gdb']
If the file ends in either of these extensions, then the filename will be found. Also, you need to set the inputDir to the correct value.
Change the inputDir path to the directory that houses your geodatabases...
Did you forget about this one?