Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gulp: How to delete a folder?

Tags:

gulp

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.

like image 829
Ng2-Fun Avatar asked Mar 21 '16 22:03

Ng2-Fun


People also ask

How do you delete a directory in C++?

For this open a command prompt, navigate to the folder where the folder you want to delete is located using cd. Then use command rmdir followed by the name of the folder you want to delete. After that you can simply use command dir to check if the folder has been deleted.

What does gulp clean do?

gulp. task('clean:build', function() { return del. sync('build'); }); The above task will clean entire build. The clean task clears any image catches and removes any old files present in build.


2 Answers

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

like image 130
zachkadish Avatar answered Nov 16 '22 05:11

zachkadish


According to the documentation : The glob pattern ** matches all children and the parent. You have to explicitly ignore the parent directories too

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

More info available here : del documentation

like image 45
rdhainaut Avatar answered Nov 16 '22 06:11

rdhainaut