Search code examples
gulp

Gulp: How to delete a folder?


I use the del package to delete a folder:

gulp.task('clean', function(){
    return del('dist/**/*', {force:true});
});

...But is there any easy way to delete the dist folder and all of its contents if it contains many subdirectories [recursively]?

Ps: I don't want to do it this way: dist/**/**/**/**/**/**/..., when there are many subdirectories.


Solution

  • your code should look like this:

    gulp.task('clean', function(){
         return del('dist/**', {force:true});
    });
    

    according to the npm del docs "**" deletes all the subdirectories of dist (ps: don't delete dist folder):

    "The glob pattern ** matches all children and the parent."

    reference