22

I am using this file matching in gulp:

'content/css/*.css'

But I would like to only include the files that do not start with an underscore. Can someone tell me how I can do this?

Here's the code:

gulp.task('less', function () {
    gulp.src('content/less/*.less')
        .pipe(less())
        .pipe(gulp.dest('content/css'));
});
Mark Amery
  • 143,130
  • 81
  • 406
  • 459
Alan2
  • 23,493
  • 79
  • 256
  • 450

5 Answers5

44

If Gulp wildcards are like shell wildcards:

content/css/[^_]*.css

The ^ at the beginning of a character set means to match any characters not in the set.

Barmar
  • 741,623
  • 53
  • 500
  • 612
8

You can add a second glob whitch will filter files or folders with an underscore.

For ignore folders I use:

gulp.src(['./src/**/*.html', '!**/_*/**'])

'!**/_*/**' will filter folders that start with an underscore.

Denis535
  • 3,407
  • 4
  • 25
  • 36
2

Use this plugin https://github.com/robrich/gulp-ignore

var gulpIgnore = require('gulp-ignore');
var condition = '_*.css'; //exclude condition

gulp.task('less', function() {
  gulp.src('content/less/*.less')
    .pipe(gulpIgnore.exclude(condition))
    .pipe(less())
    .pipe(gulp.dest('/dist/'));
});

I think gulp supports file glob not full-regex, But You can give a try to content/css/[^_]*.less

Pratap Koritala
  • 1,557
  • 14
  • 16
  • I'm very open to your new suggestiong but can you check my updated question where I show the code that's being used. I think my version might be a bit simpler as it does not need gulp-ignore. I welcome your comments on this. Thanks – Alan2 Dec 29 '14 at 13:12
  • Check the updated post, But your code is including all the files ending with .less I am not sure if gulp by default supports full regex in filenames!! – Pratap Koritala Dec 29 '14 at 13:17
1

You could use this regex.

content/css/[^_].*\.css

Add $ at the last if necessary.

Avinash Raj
  • 172,303
  • 28
  • 230
  • 274
  • Can you tell me what the ".*\" in the middle does here? Also I am looking for files that do not start with an underscore. – Alan2 Dec 29 '14 at 13:10
  • `[^_]` matches the first letter of the filename, only if it's not an underscore. So the following `.*` matches any character non-greedily, it matches underscores also. And the final `.css` asserts that the filenames must end with .css` – Avinash Raj Dec 29 '14 at 13:15
0

For those using Python (coming from Google like me), the correct would be:

import glob
glob.glob('content/css/[!_]*.css')
Fernando Wittmann
  • 1,991
  • 20
  • 16