I have a geodatabase and I would like to be able to delete layers in there easily using ArcPy. Also select which type of files.

Example: delete all file tables from the gdb or all layers.


env.workspace = r"path.gdb"
for i in arcpy.ListFeatureClasses():
    #how to delete?
  • 2
    Just something to consider, if you wanted to purge a geodatabase completly (i.e. remove all it's contents) it will be quicker to delete the geodatabase itself and create another. You would do that if you don't care about any domains or metadata.
    – Hornbydd
    Oct 25, 2018 at 21:09
  • 1
    Be aware that geodatabases do not contain layers but they can contain feature classes that layers in a map or layer-file are using as their source.
    – PolyGeo
    Oct 25, 2018 at 21:21

1 Answer 1

env.workspace = r"path.gdb"
fc_list = arcpy.ListFeatureClasses()
tables = arcpy.ListTables()
ds_list = arcpy.ListDatasets()

#feature classes
for fc in fc_list:

for table in tables:

#data sets
for ds in ds_list:

There are many options to modify each of list so head to help links to get more info.

Help links:

feature clases - http://pro.arcgis.com/en/pro-app/arcpy/functions/listfeatureclasses.htm

tables - http://pro.arcgis.com/en/pro-app/arcpy/functions/listtables.htm

data sets - http://pro.arcgis.com/en/pro-app/arcpy/functions/listdatasets.htm

delete - http://pro.arcgis.com/en/pro-app/tool-reference/data-management/delete.htm

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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