Delete empty Feature Classes from GDB

6305
16
Jump to solution
04-10-2015 07:02 AM
ThomasWhite4
New Contributor II

Hello,

I have many feature classes in multiple gdbs that have empty feature classes. Is there anyway to automate a process to look through each .gdb, find the empty feature classes, and to delete the empty feature classes from the .gdb?

Thank you for your time all!

Regards,

Tom

0 Kudos
16 Replies
JamesCrandall
MVP Frequent Contributor

There's a scroll bar on the bottom of the code area.  It's all there!

If that is what you needed then please mark it as the answer.  If not then mark Christian's answer as the solution since he posted it up first.  It helps others find the answer if they search for the same thing.

0 Kudos
ThomasWhite4
New Contributor II

Sorry about that, I am new to this environment. I am not returning anything on the code listed above. After running module, nothing is returned. Anything on this?

0 Kudos
JamesCrandall
MVP Frequent Contributor

Post your code exactly as you have it written.  We can't guess.

ThomasWhite4
New Contributor II

import arcpy

arcpy.env.workspace = "D:\test_script\clip.gdb"

fcList = arcpy.ListFeatureClasses()

for fc in fcList:

     result = arcpy.GetCount_management(fc)

     count = int(result.getOutput(0))

     if count == 0:

          arcpy.Delete_management(fc)

0 Kudos
JamesCrandall
MVP Frequent Contributor

Your workspace is incorrect or doesn't exist.  Double-check that path/name/etct..  This will print "fcList is None!" if it doesn't find it:

import arcpy
arcpy.env.workspace = "D:\test_script\clip.gdb"
fcList = arcpy.ListFeatureClasses()
if not fcList is None:
 for fc in fcList:
      result = arcpy.GetCount_management(fc)
      count = int(result.getOutput(0))
      if count == 0:
          arcpy.Delete_management(fc)
else:
 print "fcList is None!"
ThomasWhite4
New Contributor II

All works and all is fixed! Thank you for your time!

JoshuaBixby
MVP Esteemed Contributor

This is the best suggestion.  Using ArcPy Walk is by far the most Pythonic approach to enumerating data sets.