How to delete the empty feature class from gdb or mdb arcgis 10.4.1

3383
7
Jump to solution
07-03-2017 05:04 AM
santhoshp
New Contributor III

Dear Friends,

Please find the attached gdb. How to delete the empty feature class from gdb.

Thanks

Santhosh

0 Kudos
1 Solution

Accepted Solutions
AlexanderBrown5
Occasional Contributor II

Santhosh,

You can manually right click on the tables in ArcCatalog and select "delete".  You could also write a python script to loop through each feature class, and where total count = 0, run the tool that Dan suggested.

Something like:

import arcpy
from arcpy import env
env.workspace = 'D:/YourPathHere/Power.mdb'

data_sets = arcpy.ListDatasets()

for item in data_sets:
    fcList = arcpy.ListFeatureClasses('', '', item)
    for item in fcList:
        fcLength = arcpy.GetCount_management(item)
        if int(fcLength.getOutput(0)) == 0:
            arcpy.Delete_management(item)
‍‍‍‍‍‍‍‍‍‍‍‍

View solution in original post

7 Replies
DanPatterson_Retired
MVP Esteemed Contributor

the Delete tool pretty well covers how to delete a featureclass... with a series of "can't do".  You will have to elaborate why you can't delete one (ps, see the code example

AlexanderBrown5
Occasional Contributor II

Santhosh,

You can manually right click on the tables in ArcCatalog and select "delete".  You could also write a python script to loop through each feature class, and where total count = 0, run the tool that Dan suggested.

Something like:

import arcpy
from arcpy import env
env.workspace = 'D:/YourPathHere/Power.mdb'

data_sets = arcpy.ListDatasets()

for item in data_sets:
    fcList = arcpy.ListFeatureClasses('', '', item)
    for item in fcList:
        fcLength = arcpy.GetCount_management(item)
        if int(fcLength.getOutput(0)) == 0:
            arcpy.Delete_management(item)
‍‍‍‍‍‍‍‍‍‍‍‍
santhoshp
New Contributor III
Thanks for reply but I am getting error.
Below the Snapshot .

My Path :E:\YourPathHere\Power.mdb.

Thanks

Santhosh

0 Kudos
DanPatterson_Retired
MVP Esteemed Contributor

YourPathHere was changed in your real script, wasn't it? and does it exist

JoshuaBixby
MVP Esteemed Contributor

Do add to Dan's question, please post the specific code generating the error and the whole error message. 

0 Kudos
AlexanderBrown5
Occasional Contributor II

Santhosh,

If you are running my snippet from above (looks like you are from your error message attached)...your syntax is incorrect based on improper spacing.  

I copied my snippet directly into idle and did not have an issue, but it looks like something got out of alignment in your error.  

Please make sure your indentation is correct:

10 Common Python Errors of Beginning ArcGIS Programmers | 

2.1.7 Indentation 

Make sure your Power.mdb is actually located here "E:\YourPathHere\Power.mdb."  You could have updated this path to something else, I was literally saying "Your path on your computer to your access database here."   You created a new path instead of updating the line within the code.

~Alex

0 Kudos
santhoshp
New Contributor III

Hi Alex,

Thank you so much for your help.

Santhosh