【问题标题】:What is the glob pattern matching all files that don't start with an underscore ignoring those in directories that start with an underscore?什么是匹配所有不以下划线开头的文件的 glob 模式,而忽略以下划线开头的目录中的文件?
【发布时间】:2016-04-06 16:12:02
【问题描述】:

给定目录结构:

a/
  b/
    _private/
      notes.txt
    c/
      _3.txt
      1.txt
      2.txt
    d/
      4.txt
    5.txt

如何编写一个选择以下路径的 glob 模式(与 npm 模块 glob 兼容)?

a/b/c/1.txt
a/b/c/2.txt
a/b/d/4.txt
a/b/5.txt

这是我尝试过的:

// Find matching file paths inside "a/b/"...
glob("a/b/[!_]**/[!_]*", (err, paths) => {
    console.log(paths);
});

但这只会发出:

a/b/c/1.txt
a/b/c/2.txt
a/b/d/4.txt

【问题讨论】:

    标签: node.js glob minimatch


    【解决方案1】:

    经过一些试验和错误(以及grunt (minimatch/glob) folder exclusion 的帮助),我发现以下似乎达到了我正在寻找的结果:

    // Find matching file paths inside "a/b/"...
    glob("a/b/**/*", {
        ignore: [
            "**/_*",        // Exclude files starting with '_'.
            "**/_*/**"  // Exclude entire directories starting with '_'.
        ]
    }, (err, paths) => {
        console.log(paths);
    });
    

    【讨论】:

      猜你喜欢
      • 2015-02-25
      • 2016-03-30
      • 1970-01-01
      • 2017-09-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多