Hello,
I am running into issues deleting empty feature classes from a geodatabase. The original source code is from this thread: How to delete the empty dataset from gdb. The error I am encountering is appearing on line 20 when the fc variable is being called to GetCount
count <SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.5); border: 0px; font-weight: inherit;">=</SPAN> GetCount<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">(</SPAN>fc<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">)</SPAN>
Error message:
"ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000732: Input Rows: Dataset C:\path\to\folder\geodatabase\featureclass does not exist or is not supported
Failed to execute (GetCount)"
The odd thing is the feature class does exist and the error only appears on some file geodatabases. My initial thoughts are there was an issue converting this script into the toolbox as the fgdb variable is set to arcpy.GetParameter(0) - also have tried arcpy.GetParameterasText(0) or just pasting the path directly into the variable as such r'C:\path\to\folder\geodatabase'. Upon debugging, the path to the feature class is correct so no issues there. I've reviewed Error: 000732: Dataset does not exist or is not supported but none of the workarounds/solutions apply here...
This script is run on several different file geodatabases with the same schema. Some run with no issues at all while other cause this error to appear. The theory right now is a long path name is causing the issue? I know running geoprocessing tools there seems to be a limit on workspace names and/or the length of the path. We moved a geodatabase that was causing issues to a shorter path and abbreviated the geodatabase name; afterwords, it worked.
Really curious about what is going on here. Thanks for the help.
<SPAN class="" style="color: #0077aa; border: 0px; font-weight: inherit;">def</SPAN> <SPAN class="" style="color: #d74444; border: 0px; font-weight: inherit;">main</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">(</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">)</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">:</SPAN>
<SPAN class="" style="color: #0077aa; border: 0px; font-weight: inherit;">import</SPAN> arcpy
<SPAN class="" style="color: #0077aa; border: 0px; font-weight: inherit;">import</SPAN> os
fgdb <SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.5); border: 0px; font-weight: inherit;">=</SPAN> r<SPAN class="" style="color: #669900; border: 0px; font-weight: inherit;">'C:\GeoNet\DeleteEmpty\SSUC_FGDB_V3.gdb'</SPAN>
<SPAN class="" style="color: slategray; border: 0px; font-weight: inherit;"># list feature datasets</SPAN>
arcpy<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">.</SPAN>env<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">.</SPAN>workspace <SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.5); border: 0px; font-weight: inherit;">=</SPAN> fgdb
fdss <SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.5); border: 0px; font-weight: inherit;">=</SPAN> arcpy<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">.</SPAN>ListDatasets<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">(</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">)</SPAN>
fdss<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">.</SPAN>append<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">(</SPAN><SPAN class="" style="color: #669900; border: 0px; font-weight: inherit;">''</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">)</SPAN>
<SPAN class="" style="color: slategray; border: 0px; font-weight: inherit;"># loop through feature datasets to delete empty ones</SPAN>
<SPAN class="" style="color: #0077aa; border: 0px; font-weight: inherit;">print</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">(</SPAN><SPAN class="" style="color: #669900; border: 0px; font-weight: inherit;">"Delete empty featureclasses"</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">)</SPAN>
<SPAN class="" style="color: #0077aa; border: 0px; font-weight: inherit;">for</SPAN> fds <SPAN class="" style="color: #0077aa; border: 0px; font-weight: inherit;">in</SPAN> fdss<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">:</SPAN>
<SPAN class="" style="color: #0077aa; border: 0px; font-weight: inherit;">print</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">(</SPAN><SPAN class="" style="color: #669900; border: 0px; font-weight: inherit;">"Processing FDS: {}"</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">.</SPAN>format<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">(</SPAN>fds<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">)</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">)</SPAN>
fcs <SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.5); border: 0px; font-weight: inherit;">=</SPAN> arcpy<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">.</SPAN>ListFeatureClasses<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">(</SPAN><SPAN class="" style="color: #669900; border: 0px; font-weight: inherit;">'*'</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">,</SPAN> None<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">,</SPAN> fds<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">)</SPAN>
<SPAN class="" style="color: slategray; border: 0px; font-weight: inherit;"># loop through featureclasses in feature dataset</SPAN>
<SPAN class="" style="color: #0077aa; border: 0px; font-weight: inherit;">for</SPAN> fc_name <SPAN class="" style="color: #0077aa; border: 0px; font-weight: inherit;">in</SPAN> fcs<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">:</SPAN>
fc <SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.5); border: 0px; font-weight: inherit;">=</SPAN> os<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">.</SPAN>path<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">.</SPAN>join<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">(</SPAN>fgdb<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">,</SPAN> fds<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">,</SPAN> fc_name<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">)</SPAN>
count <SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.5); border: 0px; font-weight: inherit;">=</SPAN> GetCount<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">(</SPAN>fc<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">)</SPAN>
<SPAN class="" style="color: #0077aa; border: 0px; font-weight: inherit;">if</SPAN> count <SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.5); border: 0px; font-weight: inherit;">==</SPAN> <SPAN class="" style="color: #990000; border: 0px; font-weight: inherit;">0</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">:</SPAN>
<SPAN class="" style="color: slategray; border: 0px; font-weight: inherit;"># if fc is empty, delete it</SPAN>
<SPAN class="" style="color: #0077aa; border: 0px; font-weight: inherit;">print</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">(</SPAN><SPAN class="" style="color: #669900; border: 0px; font-weight: inherit;">" - Deleting: {}"</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">.</SPAN>format<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">(</SPAN>fc_name<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">)</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">)</SPAN>
arcpy<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">.</SPAN>Delete_management<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">(</SPAN>fc<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">)</SPAN>
<SPAN class="" style="color: #0077aa; border: 0px; font-weight: inherit;">else</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">:</SPAN>
<SPAN class="" style="color: #0077aa; border: 0px; font-weight: inherit;">print</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">(</SPAN><SPAN class="" style="color: #669900; border: 0px; font-weight: inherit;">" - Skip: {}"</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">.</SPAN>format<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">(</SPAN>fc_name<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">)</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">)</SPAN>
<SPAN class="" style="color: slategray; border: 0px; font-weight: inherit;"># delete empty feature datasets</SPAN>
<SPAN class="" style="color: #0077aa; border: 0px; font-weight: inherit;">print</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">(</SPAN><SPAN class="" style="color: #669900; border: 0px; font-weight: inherit;">"Delete empty feature datasets"</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">)</SPAN>
fdss <SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.5); border: 0px; font-weight: inherit;">=</SPAN> arcpy<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">.</SPAN>ListDatasets<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">(</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">)</SPAN>
<SPAN class="" style="color: #0077aa; border: 0px; font-weight: inherit;">for</SPAN> fds <SPAN class="" style="color: #0077aa; border: 0px; font-weight: inherit;">in</SPAN> fdss<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">:</SPAN>
<SPAN class="" style="color: #0077aa; border: 0px; font-weight: inherit;">print</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">(</SPAN><SPAN class="" style="color: #669900; border: 0px; font-weight: inherit;">"Processing FDS: {}"</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">.</SPAN>format<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">(</SPAN>fds<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">)</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">)</SPAN>
fcs <SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.5); border: 0px; font-weight: inherit;">=</SPAN> arcpy<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">.</SPAN>ListFeatureClasses<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">(</SPAN><SPAN class="" style="color: #669900; border: 0px; font-weight: inherit;">'*'</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">,</SPAN> None<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">,</SPAN> fds<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">)</SPAN>
<SPAN class="" style="color: #0077aa; border: 0px; font-weight: inherit;">if</SPAN> len<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">(</SPAN>fcs<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">)</SPAN> <SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.5); border: 0px; font-weight: inherit;">==</SPAN> <SPAN class="" style="color: #990000; border: 0px; font-weight: inherit;">0</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">:</SPAN>
<SPAN class="" style="color: #0077aa; border: 0px; font-weight: inherit;">print</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">(</SPAN><SPAN class="" style="color: #669900; border: 0px; font-weight: inherit;">" - Delete FDS {}"</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">.</SPAN>format<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">(</SPAN>fds<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">)</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">)</SPAN>
arcpy<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">.</SPAN>Delete_management<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">(</SPAN>fds<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">)</SPAN>
<SPAN class="" style="color: #0077aa; border: 0px; font-weight: inherit;">else</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">:</SPAN>
<SPAN class="" style="color: #0077aa; border: 0px; font-weight: inherit;">print</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">(</SPAN><SPAN class="" style="color: #669900; border: 0px; font-weight: inherit;">" - Keep FDS {}"</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">.</SPAN>format<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">(</SPAN>fds<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">)</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">)</SPAN>
<SPAN class="" style="color: slategray; border: 0px; font-weight: inherit;"># delete empty tables</SPAN>
<SPAN class="" style="color: #0077aa; border: 0px; font-weight: inherit;">print</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">(</SPAN><SPAN class="" style="color: #669900; border: 0px; font-weight: inherit;">"Delete empty tables"</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">)</SPAN>
tbls <SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.5); border: 0px; font-weight: inherit;">=</SPAN> arcpy<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">.</SPAN>ListTables<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">(</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">)</SPAN>
<SPAN class="" style="color: #0077aa; border: 0px; font-weight: inherit;">for</SPAN> tbl_name <SPAN class="" style="color: #0077aa; border: 0px; font-weight: inherit;">in</SPAN> tbls<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">:</SPAN>
tbl <SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.5); border: 0px; font-weight: inherit;">=</SPAN> os<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">.</SPAN>path<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">.</SPAN>join<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">(</SPAN>fgdb<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">,</SPAN> tbl_name<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">)</SPAN>
count <SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.5); border: 0px; font-weight: inherit;">=</SPAN> GetCount<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">(</SPAN>tbl<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">)</SPAN>
<SPAN class="" style="color: #0077aa; border: 0px; font-weight: inherit;">if</SPAN> count <SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.5); border: 0px; font-weight: inherit;">==</SPAN> <SPAN class="" style="color: #990000; border: 0px; font-weight: inherit;">0</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">:</SPAN>
<SPAN class="" style="color: slategray; border: 0px; font-weight: inherit;"># if tbl is empty, delete it</SPAN>
<SPAN class="" style="color: #0077aa; border: 0px; font-weight: inherit;">print</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">(</SPAN><SPAN class="" style="color: #669900; border: 0px; font-weight: inherit;">" - Deleting: {}"</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">.</SPAN>format<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">(</SPAN>tbl_name<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">)</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">)</SPAN>
arcpy<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">.</SPAN>Delete_management<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">(</SPAN>tbl<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">)</SPAN>
<SPAN class="" style="color: #0077aa; border: 0px; font-weight: inherit;">else</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">:</SPAN>
<SPAN class="" style="color: #0077aa; border: 0px; font-weight: inherit;">print</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">(</SPAN><SPAN class="" style="color: #669900; border: 0px; font-weight: inherit;">" - Skip: {}"</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">.</SPAN>format<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">(</SPAN>tbl_name<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">)</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">)</SPAN>
<SPAN class="" style="color: #0077aa; border: 0px; font-weight: inherit;">def</SPAN> <SPAN class="" style="color: #d74444; border: 0px; font-weight: inherit;">GetCount</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">(</SPAN>fc<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">)</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">:</SPAN>
<SPAN class="" style="color: #0077aa; border: 0px; font-weight: inherit;">return</SPAN> int<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">(</SPAN>arcpy<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">.</SPAN>GetCount_management<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">(</SPAN>fc<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">)</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">.</SPAN>getOutput<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">(</SPAN><SPAN class="" style="color: #990000; border: 0px; font-weight: inherit;">0</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">)</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">)</SPAN>
<SPAN class="" style="color: #0077aa; border: 0px; font-weight: inherit;">if</SPAN> __name__ <SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.5); border: 0px; font-weight: inherit;">==</SPAN> <SPAN class="" style="color: #669900; border: 0px; font-weight: inherit;">'__main__'</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">:</SPAN>
main<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">(</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">)</SPAN>