I wrote a script that creates a GDB using a designated parish/county name and then does a selection by location and extracts from another db to the newly created db. This all works fine but there are some empty feature classes in the db that I want to remove.
The code below recognizes the empty fc’s but does not delete them. In the results, it creates the message saying that it deleted the fc but when I check the geodatabase everything was stored in, the empty fc’s are still there. This portion of the code runs perfectly fine when adjusted for other scripts that just involve shapefiles in a folder. Is it an issue with the gdb that I’m not aware of?
arcpy.env.workspace = output + r'/' + parish + '.gdb'
for file in arcpy.ListFeatureClasses():
layerName = arcpy.Describe(file).baseName
arcpy.MakeFeatureLayer_management(file, layerName)
if int(arcpy.GetCount_management(layerName).getOutput(0)) == 0:
arcpy.Delete_management(file)
arcpy.AddMessage('Deleted "{}" because it contains no features!'.format(file))