Depth-first cleaning of empty directories/subdirectories
frickenate opened this issue · 4 comments
Is it in any way possible to force a depth-first search? This is especially useful/needed when combined with a filter function.
I have a directory with empty descendents:
build/
first-empty-dir/
second-empty-dir/
third-empty-dir/
and need to delete all empty directories within build/
(not all directories are empty, so I can't just clean the entire build directory).
My best attempt thus far looks like this:
var fs = require('fs');
grunt.config('clean', {
empty: {
src: ['build/**/*', 'build/*'],
filter: function (path) {
return grunt.file.isDir(path) && fs.readdirSync(path).length === 0;
}
}
});
grunt.task.run('clean');
But clearly a breadth-first search is performed which first finds first-empty-directory
which is not yet empty. If there isn't a native way with grunt's glob functionality, is there a clean way to define or run a grunt task that executes iteratively until some condition is met (ie: no paths were deleted in the most recent execution)? Otherwise I fear having to write a custom task to perform a depth-first search.
+1 on this!
+1 ;-)
A bit late to the party, but +1
Almost a year later than the last request +1