Dear Friends,
Please find the attached gdb. How to delete the empty feature class from gdb.
Thanks
Santhosh
Santhosh,
You can manually right click on the tables in ArcCatalog and select "delete". You could also write a python script to loop through each feature class, and where total count = 0, run the tool that Dan suggested.
Something like:
<SPAN class="keyword token">import</SPAN> arcpy <SPAN class="keyword token">from</SPAN> arcpy <SPAN class="keyword token">import</SPAN> env env<SPAN class="punctuation token">.</SPAN>workspace <SPAN class="operator token">=</SPAN> <SPAN class="string token">'D:/YourPathHere/Power.mdb'</SPAN> data_sets <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>ListDatasets<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">for</SPAN> item <SPAN class="keyword token">in</SPAN> data_sets<SPAN class="punctuation token">:</SPAN> fcList <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>ListFeatureClasses<SPAN class="punctuation token">(</SPAN><SPAN class="string token">''</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">''</SPAN><SPAN class="punctuation token">,</SPAN> item<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">for</SPAN> item <SPAN class="keyword token">in</SPAN> fcList<SPAN class="punctuation token">:</SPAN> fcLength <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>GetCount_management<SPAN class="punctuation token">(</SPAN>item<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">if</SPAN> int<SPAN class="punctuation token">(</SPAN>fcLength<SPAN class="punctuation token">.</SPAN>getOutput<SPAN class="punctuation token">(</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">==</SPAN> <SPAN class="number token">0</SPAN><SPAN class="punctuation token">:</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Delete_management<SPAN class="punctuation token">(</SPAN>item<SPAN class="punctuation token">)</SPAN> <SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
the Delete tool pretty well covers how to delete a featureclass... with a series of "can't do". You will have to elaborate why you can't delete one (ps, see the code example
My Path :E:\YourPathHere\Power.mdb.
YourPathHere was changed in your real script, wasn't it? and does it exist
Do add to Dan's question, please post the specific code generating the error and the whole error message.
If you are running my snippet from above (looks like you are from your error message attached)...your syntax is incorrect based on improper spacing.
I copied my snippet directly into idle and did not have an issue, but it looks like something got out of alignment in your error.
Please make sure your indentation is correct:
10 Common Python Errors of Beginning ArcGIS Programmers |
2.1.7 Indentation
Make sure your Power.mdb is actually located here "E:\YourPathHere\Power.mdb." You could have updated this path to something else, I was literally saying "Your path on your computer to your access database here." You created a new path instead of updating the line within the code.
~Alex
Hi Alex,
Thank you so much for your help.
Aangemelde leden kunnen berichten plaatsen, updates volgen en meer. Nieuw hier? Registreer een gratis account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.