Delete all Features and Tables within a FGDB?

106
2
Jump to solution
03-07-2019 10:37 AM
vonmoosa
MVP

What's the simplest way to delete all of the contents in a FGDB using arcpy?

0 Kudos
1 Solution

Accepted Solutions
vonmoosa
MVP

I was able to get the following code to work.

import arcpy  
arcpy.env.workspace = r"XXXXXXXXXXXXXXXXXXX"  
for objFeatureClass in arcpy.ListFeatureClasses():  
    arcpy.Delete_management(objFeatureClass)
for objTables in arcpy.ListTables():  
    arcpy.Delete_management(objTables)
print "Process Complete"

View solution in original post

2 Replies
DanPatterson_Retired
MVP Esteemed Contributor

If there will be nothing left, just delete the gdb. then recreate it with the same name.

Or is there something else that needs to be maintained? 

vonmoosa
MVP

I was able to get the following code to work.

import arcpy  
arcpy.env.workspace = r"XXXXXXXXXXXXXXXXXXX"  
for objFeatureClass in arcpy.ListFeatureClasses():  
    arcpy.Delete_management(objFeatureClass)
for objTables in arcpy.ListTables():  
    arcpy.Delete_management(objTables)
print "Process Complete"