我具有以下文件层次结构:
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)
以下glob应该起作用:
['./scripts/**/*', '!./scripts/*']
第一部分将包括所有子目录和所有文件,第二部分将排除起始目录中的文件。