Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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

share|improve this question
    
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 Jan 24 '12 at 23:01

1 Answer 1

up vote 5 down vote accepted

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

share|improve this answer
1  
Looks good, but I think you want ListTables in this case, Hairy. –  Nathanus Jan 24 '12 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 Jan 24 '12 at 15:24
    
worked great, thanks! –  jay Jan 26 '12 at 3:03

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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