I want to delete about 25 datasets that are empty from my gdb file which consists 30 datasets. I am invoking pPthon window and trying to execute this script:

import arcpy
from arcpy import env
env.workspace =r"D:\test\E44M11_HYD_UTM44.gdb"

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:

But just after 2 layers deletion it prompts this error message.

Screen shot How can I fix this issue?

  • 1
    Add print item after for item in fcList to see what is causing the error. You are probably listing something incompatible with GetCount. For example what if one listed item from ListDatasets is an empty feature dataset, then you are passing a empty list to GetCount – BERA Jul 4 '20 at 17:15
  • 3
    Please edit your question to include the error as text rather than or in addition to the image. Images can be hard to read on some devices, and having text makes the error searchable (so future users can find it if they have the same issue). – Midavalo Jul 4 '20 at 17:46
  • 2
    Eliminating the image is worse than replacing the image with the exact error text. – Vince Jul 5 '20 at 1:41

I believe the problem is that you are using the variable name item in the outer AND inner loop, so you are overwriting the feature dataset name and confusing yourself. Don't do that! It also makes your code much harder to decipher, so always use different variable names for nested loops.

That said having got a handle on a FeatureDataset and then a list of FeatureClasses within the FeatureDataset you then try to delete it if it is empty but now item is a featureClass name but your workspace is pointing to the geodatabase, not the the geodatabase AND your FeatureDataset name. You need to construct the FULL PATH to the featureclass to delete it.

Something like myPath = arcpy.env.workspace + "\\" + item + "\\" + item2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.