如何使用glob来忽略以下划线开头的文件?

时间:2014-12-29 12:55:59

标签: gulp glob

我在gulp中使用这个文件匹配:

'content/css/*.css'

但我想只包含以下划线开头的文件。有人能告诉我怎么做吗?

以下是代码:

gulp.task('less', function () {
    gulp.src('content/less/*.less')
        .pipe(less())
        .pipe(gulp.dest('content/css'));
});

4 个答案:

答案 0 :(得分:35)

如果Gulp通配符就像shell通配符:

content/css/[^_]*.css

字符集开头的^表示匹配集中的任何字符

答案 1 :(得分:7)

你可以添加第二个glob whitch,用下划线过滤文件或文件夹。

对于我使用的忽略文件夹:

           String mCurrentPhotoPath;  // is stored at the global level
           .....
           String fileName = name.replace(" ", "");
            fileName = fileName + suffix + ".jpg";
            mCurrentPhotoPath = fileName;
            ContentValues values = new ContentValues();
            values.put(MediaStore.Images.Media.TITLE, mCurrentPhotoPath);
            values.put(MediaStore.Images.Media.DESCRIPTION, "Image capture by camera");
                 imageUri = getContentResolver().insert(
                 MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);

if (requestCode == RESULT_LOAD_IMAGE) { if(imageUri != null) selectedImage = imageUri; else { if(mCurrentPhotoPath != null) { // mCurrentPhotoPath returns null; File file = new File(Environment.getExternalStorageDirectory().getPath(), mCurrentPhotoPath); selectedImage = Uri.fromFile(file); } else { Toast.makeText(getApplicationContext(), "Photo not captured", Toast.LENGTH_LONG).show(); return; } } 将过滤以下划线开头的文件夹。

答案 2 :(得分:2)

使用此插件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/'));
});

我认为gulp支持文件 glob not full-regex ,但你可以尝试content/css/[^_]*.less

答案 3 :(得分:1)

你可以使用这个正则表达式。

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

如有必要,请在最后添加$

相关问题