I am trying to delete all feature classes, tables and datasets from a file database and the issue is sometimes it works and sometimes it doesn't. I trying the following but none of them works consistently. My thought is that, os.path.exists would be more reliable.
import arcpy, os
def deletePI():
try:
arcpy.env.workspace = "C:/Temp/DashboardPI.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)
except:
pass
import arcpy, os
def deletePI():
try:
arcpy.env.workspace = "C:/Temp/DashboardPI.gdb"
if os.path.exists("C:/Temp/BoardPI.gdb/PI_Taxp") == True:
arcpy.Delete_management(r"C:/Temp/boardPI.gdb/PI_Taxp")