[GIS] Deleting contents from geodatabase in ArcPy

arcpydelete

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.

Code:

env.workspace = r"path.gdb"
for i in arcpy.ListFeatureClasses():
    #how to delete?

Best Answer

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

#feature classes
for fc in fc_list:
    arcpy.Delete_management(fc)

#tables
for table in tables:
    arcpy.Delete_management(table)

#data sets
for ds in ds_list:
    arcpy.Delete_management(ds)

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