2017-06-01 58 views
2

我有一个吞噬观察脚本,监视我的图像目录中的更改,然后处理图像。问题在于,为网络保存的photoshop会将临时文件放入目录中,然后非常快速地重命名它们,从而影响我的图像处理脚本。我想从观察脚本中排除它们。gulp-watch排除具有特定字符集的文件

的临时文件被格式化为使moog-mftrem_tmp489245944

我想用_tmp字符串排除,但不知道如何在一个文件名的中间排除字符。这是我已经尝试过,但似乎没有工作:

gulp.task('watch', function() { 
    gulp.watch(['app/images/pedals/*.png','!app/images/pedals/*_tmp*'], ['images']); 
}); 

感谢您的任何帮助!

回答

1

虽然临时文件没有扩展名,但如果不指定glob文件夹,则glob路径不知道该如何操作。它只是一个文件夹的路径,实际上它找不到与你的glob匹配的文件夹名称。

尝试:

gulp.task('watch', function() { 
    gulp.watch(['app/images/pedals/*.png','!app/images/pedals/*_tmp*.*'], ['images']); 
}); 

注意额外的:*(期星号)

为了完整性我想补充递归globstar/**/

gulp.task('watch', function() { 
    gulp.watch(['app/images/pedals/**/*.png','!app/images/pedals/**/*_tmp*.*'], ['images']); 
}); 
+0

这似乎是票......谢谢! –

0

考虑使用“一口过滤器”:

const gulp = require('gulp'); 
const filter = require('gulp-filter'); 


gulp.task('watch', function() { 
    gulp.watch('app/images/pedals/*.png', ['images']); 
}); 

const f = filter(file => file.path.includes('tmp')); 

gulp.task('images', function() { 
    return gulp.src('app/images/pedals/*.png') 
     .pipe(f) 
     .pipe(gulp.dest('./build')) 

}); 
相关问题