通配模式可排除目录中的文件,但包含子目录

sen*_*ett 2 glob

我具有以下文件层次结构:

scripts
    someConfigFile.js
    anotherConfigFile.js

    someModuleDirectory
        someModule.js

    anotherModuleDirectory
        anotherModule.js

        subDirectory
            thirdModule.js
Run Code Online (Sandbox Code Playgroud)

我想匹配模块目录中的所有文件,但scripts使用Glob排除目录中包含的配置文件:

var glob = require('glob');

console.log(glob.sync(unknownGlobPattern));
Run Code Online (Sandbox Code Playgroud)

所需输出(无序):

[
    'someModuleDirectory/someModule.js',
    'anotherModuleDirectory/anotherModule.js',
    'anotherModuleDirectory/subDirectory/thirdModule.js'
]
Run Code Online (Sandbox Code Playgroud)

Jur*_*els 5

以下glob应该起作用:

['./scripts/**/*', '!./scripts/*']

第一部分将包括所有子目录和所有文件,第二部分将排除起始目录中的文件。

  • 您好,由于 CLI 中的使用,当需要将其全部包含到一个“命令”中时,我遇到了类似的问题 (2认同)