NodeJS&Glob:从一个字符串中的 glob 选择中排除具有任意文件扩展名的任意文件

NodeJS&Glob: exclude arbitrary files with arbitrary filename extensions from glob selections in one string

如何从 glob 中排除具有任意文件扩展名的任意文件 选择?

例如:我们需要 C:\Users\User1\projectname\src\markup 中的所有 .pug.haml 文件 除了 index.pug(但 index.haml 可以)。

glob

'C:\Users\User1\projectname\src\markup\!(index).+(pug|haml)'

排除了index.pugindex.haml——这不是我们想要的,也没有足够的灵活性。

让我们说清楚:

  1. 在这个问题中我们不需要通过 glob 接收文件 - 目标只是创建单个 glob 选择。所以像 globby(['C:\Users\User1\projectname\src\markup\*.+(pug|haml)', '!C:\Users\User1\projectname\src\markup\index.pug']); 这样的解决方案是 不符合这个问题。
  2. 如果不可能 - 从 glob 中排除具有任意扩展名的任意文件 - 请说例如。

我试过了

minimatch(
    'C:\Users\bokovgleb\projectname\src\src\index.pug',
    'C:\Users\bokovgleb\projectname\src\src\*(*.pug|!(index.pug))'
)

基于comment to this answer。它returns true...

For example: we need all .pug and .haml files in C:\Users\User1\projectname\src\markup except index.pug (but index.haml is O'K).

我想出了

/markup/!(*index){.pug,.haml,index.haml}

您可以使用 globster.xyz

进行测试