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

∥☆過路亽.° 提交于 2020-01-04 21:35:36

问题


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?


回答1:


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'));
});


来源:https://stackoverflow.com/questions/30678243/gulp-copy-single-file-src-pipe-dest-with-wildcarded-directory

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!