kspearrin
kspearrin

Reputation: 10788

Gulp copy single file (src pipe dest) with wildcarded directory

I am trying to copy a specific file src C:\Project\dir1\dirv-1.0.0\tools\file.exe to a specific directory dest C:\Project\dir2\ using gulp.

The version number in dirv-1.0.0 could change in the future, so I want to wildcard the version number.

Here is the task I have for that (gulpfile.js is in C:\Project):

gulp.task('copy', function(){
    return gulp
        .src('dir1\dirv-*\tools\file.exe')
        .pipe(gulp.dest('dir2'));
});

This ends up generating the following dest file: C:\Project\dir2\dirv-1.0.0\tools\file.exe. What I want is C:\Project\dir2\file.exe.

How do I do this gulp copy task so that I can wildcard the src path but only copy file.exe to the dest path?

Upvotes: 2

Views: 2430

Answers (1)

Raspo
Raspo

Reputation: 1087

Use gulp-flatten

var gulp = require('gulp');
var flatten = require('gulp-flatten');

gulp.task('default', function(){
    return gulp.src('./dir1/dirv-*1/test.txt')
        .pipe(flatten())
        .pipe(gulp.dest('dir2'));
});

Upvotes: 3

Related Questions