skip to Main Content

I have a gulp-watch script that watches for changes in my image directory then process the images. The problem is that photoshop save for web is putting temp files in the directory and then renaming them very quickly, which trips up my image processing script. I would like to exclude them from the watch script.

The temp files are formatted as so moog-mftrem_tmp489245944

I would like to use the _tmp string to exclude, but not sure how to exclude characters in the middle of a file name. Here is what I have tried but doesn’t seem to work:

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

Thanks for any help!

2

Answers


  1. While your temp files don’t have extensions, glob paths don’t know what to do if you don’t specify one. It becomes merely a path to a folder, and indeed it doesn’t find a folder name matching your glob.

    Try:

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

    Note the extra: .* (period asterisk)

    For completeness I like to add the recursive globstar /**/

    i.e.

    gulp.task('watch', function() {
        gulp.watch(['app/images/pedals/**/*.png','!app/images/pedals/**/*_tmp*.*'], ['images']);
    });
    
    Login or Signup to reply.
  2. consider using ‘gulp-filter’ :

    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'))
    
    });
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search