gulp复制带有通配目录的单个文件(src pipe dest) [英] Gulp copy single file (src pipe dest) with wildcarded directory

查看:190
本文介绍了gulp复制带有通配目录的单个文件(src pipe dest)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将特定文件src C:\Project\dir1\dirv-1.0.0\tools\file.exe 复制到特定目录dest C:\Project\dir2\ 使用gulp。

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.

版本号 dirv-1.0.0 可能会在将来发生变化,所以我想通配符版本号。

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

这是任务我为此( gulpfile.js 位于 C:\Project 中):

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

最终生成以下dest文件: C:\ Project \\ \\dir2\dirv-1.0.0\tools\file.exe 。我想要的是 C:\Project\dir2\file.exe

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.

我该怎么做这个gulp复制任务,以便我可以通配符src路径,但只拷贝 file.exe 到dest路径中?

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?

推荐答案

使用咕嘟咕嘟

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

这篇关于gulp复制带有通配目录的单个文件(src pipe dest)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆