Search code examples
gulpgulp-rename

Renaming a directory in gulp


I'm using gulp-rename to rename a directory as follows:

gulp.task('vendor-rename-pre', function() {
  return gulp.src('src/vendor')
    .pipe(rename('vendor-dev'))
    .pipe(gulp.dest('src'));
});

However, it essentially ends up creating a new, empty directory called vendor-dev instead of renaming vendor. vendor is left as is.

So, how can I actually rename a directory using gulp?


Solution

  • There's nothing Gulp-specific about renaming a file on disk. You can just use the standard Node.js fs.rename() function:

    var fs = require('fs');
    
    gulp.task('vendor-rename-pre', function(done) {
      fs.rename('src/vendor', 'src/vendor-dev', function (err) {
        if (err) {
          throw err;
        }
        done();
      });
    });