You can add an additional filter so that it skips rows that have no files.
What you might be better off doing is starting with a Query that applies all your filters, and sort it in reverse table order. And then loop through the query instead of directly through the table.