4

I've got about 1000 tables in a geodatabse that I need to delete. They are named IntersectedBuffers_1, IntersectedBuffers_2, etc, and they're the only tables in the database.

Could someone please tell me how to delete these? I've been trying to do it from the python window. I can successfully delete individual tables with the following code:

import arcpy
arcpy.env.workspace = r"C:\Documents and Settings\Administrator\My Documents\ArcGIS\Default1.gdb"
arcpy.Delete_management("IntersectedBuffers_2")

But how can I delete all of them? I've tried things like

arcpy.Delete_management("IntersectedBuffers*.tbl")

... but I'm really just guessing! Is there a way to delete based on a shared text string, or based on teh fact that they're all tables?

Thanks in advance,

Jay

1
  • This is only an indirect answer to your question since you seem to want to use Python for it, but if you go into the geodatabase in arccatlog, and sort by type, you can then click the table at the top and hold shift then click the table at the bottom. If you hit the delete key then, all of your tables will disappear.
    – nicksan
    Commented Jan 24, 2012 at 23:01

1 Answer 1

5

What you have to do is add all of your Tables to a list, and delete the list:

arcpy.env.workspace = r"C:\Documents and Settings\Administrator\My Documents\ArcGIS\Default1.gdb"
lstTables = arcpy.ListTables("IntersectedBuffers*", "All") #all is default

#I cannot remember the delete command, but I think it is this:
for dt in lstTables:
    arcpy.Delete_management(dt)

I think this should work, but am away from my python machine, so will have a look later

Arcpy ListTables

2
  • 1
    Looks good, but I think you want ListTables in this case, Hairy.
    – Nathanus
    Commented Jan 24, 2012 at 15:22
  • Could be @Nathanus, I was pre-empting Jay meaning datasets! Could be wrong. I should have added a link to the help I think. Cheers edited now.
    – Hairy
    Commented Jan 24, 2012 at 15:24

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.