如何在使用Shell.js将一个文件夹移动到另一个文件夹时排除一些文件

时间:2019-02-18 04:10:08

标签: typescript gulp shelljs

我在结构库下面:

src
  -common
        - asd.ts
        - filter.ts
  -checking
        -hi.json
  -third-party
        -src
            -common
                   -hello.ts
                   -two.ts  
                   -three.ts

在这里,我想将文件从 third-party / src / common 移到 src / common ,但是我必须排除 three.ts 文件。

  

我像下面的bur一样害怕,它会移动所有文件:

gulp.task('common-update', function (done) {
  shelljs.cp('-rf', './third-party/angularSB/src/app/common/*', './src/app/common/');
  done();
});

2 个答案:

答案 0 :(得分:1)

shelljs的{​​{1}}函数不能要求您根据目录或通配符进行复制时排除文件。

解决此问题的选项包括:

  • 使用cp来复制集合,然后使用cp删除目标中不需要的特定文件。
  • 收集文件列表并根据您的条件过滤文件,然后使用rm分别复制每个文件。
  • 使用不支持某种排除选项的其他库,例如copyfiles

答案 1 :(得分:1)

我已经尝试过像这样

gulp.task('common-update', function (done) {
  var check = glob.sync('./third-party/src/common/*');
  for (var i = 0; i < check.length - 1; i++) {
    if (check[i].indexOf('three.ts') === -1) {
      shelljs.cp('-rf', check[i], './src/common/');
    }
  }
  done();
});