Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exclude Directory-Pattern in gulp with glob in `gulp.src`

Tags:

path

gulp

glob

I am trying to glob all files&directories with gulp.src() expcept all directories starting with the character _ (i.e. _Stuff/). How can I achieve that?

like image 505
zoma Avatar asked Jan 06 '23 15:01

zoma


1 Answers

Say you have a folder project/src that contains the following files:

file.txt
folder
folder/file.txt
folder/_subfolder
folder/_subfolder/file.txt
folder/subfolder
folder/subfolder/file.txt
_folder
_folder/file.txt
_folder/_subfolder
_folder/_subfolder/file.txt
_folder/subfolder
_folder/subfolder/file.txt

Then this task in project/Gulpfile.js:

gulp.task('default', function() {
  return gulp.src([
      'src/**/*',         //select all files
      '!src/**/_*/',      //exclude folders starting with '_'
      '!src/**/_*/**/*',  //exclude files/subfolders in folders starting with '_'
    ])
    .pipe(gulp.dest('dist'));
});

Will result in the following files being written to project/dist:

file.txt
folder
folder/file.txt
folder/subfolder
folder/subfolder/file.txt
like image 159
Sven Schoenung Avatar answered Jan 23 '23 02:01

Sven Schoenung