【问题标题】:How to exclude some files while using shelljs to move one folder to another如何在使用 shelljs 将一个文件夹移动到另一个文件夹时排除某些文件
【发布时间】:2019-02-18 04:10:07
【问题描述】:

我有下面的结构存储库:

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文件。

我已经像下面这样移动了所有文件:

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

【问题讨论】:

    标签: typescript gulp shelljs


    【解决方案1】:

    shelljscp函数在你要求它根据目录或通配符复制时不具备排除文件的能力。

    解决此问题的方法包括:

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

    【讨论】:

      【解决方案2】:

      我试过这样它可以工作

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

      【讨论】:

      • 谢谢,我很久以前也在找这个。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-08
      • 1970-01-01
      • 2010-09-08
      • 1970-01-01
      • 2013-12-08
      • 1970-01-01
      相关资源
      最近更新 更多