node.js - 匹配所有不以下划线开头的文件并忽略以下划线开头的目录中的文件的 glob 模式是什么?

标签 node.js glob minimatch

给定目录结构:

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

最佳答案

经过一些尝试和错误(以及 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);
});

关于node.js - 匹配所有不以下划线开头的文件并忽略以下划线开头的目录中的文件的 glob 模式是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34567591/

相关文章:

node.js - Glob 和 NPM Minimatch : Match all files and directories recursively except for specific directories

javascript - 用 proxyquire 模拟 MongoDB

node.js - 在没有 nodejs 服务器的情况下运行 redux 示例?

node.js - 首次加载时在Electron中启动VLC

Bash 脚本 echo 正在执行一个奇怪的替换

php - 引用 GLOB_NOSORT 标志时的 "no sorting"顺序是什么

node.js - npm 包是如何在 nodester 中管理的?

php - Glob 模式不匹配任何内容

Cypress 的ignoreTestFiles不会忽略测试

javascript - 用于忽略某些 .dot.js 文件的 Glob 模式