2

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?

Gezim
  • 7,112
  • 10
  • 62
  • 98

2 Answers2

11

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();
  });
});
Sven Schoenung
  • 30,224
  • 8
  • 65
  • 70
1

Just to answer your question you can do below to use gulp-rename to rename the file

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

The only caveat here is that the old file will remain in the same location

Aditya Singh
  • 15,810
  • 15
  • 45
  • 67
  • Right, so it's more of a copy instead of rename :) ... but I guess that can be address with `del` – Gezim Apr 04 '16 at 15:59