我想匹配给定子文件夹中的所有子文件夹。
假设我有以下目录:
test/rock/martin
test/rock/steven
test/rock/steven/coolmusik
test/rock/steven/coolmusik/newmusic
test/pop/martin
test/pop/steven
test/pop/steven/mysubdir
test/pop/steven/anothersubdir
现在我想匹配“摇滚”和“流行”中的所有内容,并限制给定名称。在这种情况下,它是“史蒂文”。
到目前为止,以下minimatch glob-rule 工作正常:
minimatch('./test', ['!*(rock|pop|steven)'], {matchBase: true}))
上述规则的翻译:
隐藏所有不在摇滚、流行和史蒂文中的东西。
但问题是:可以想象 minimatch 在这种特殊情况下不包括子目录。
我希望它像...
minimatch('./test', ['!*(rock|pop|steven|PLUS_SUBDIRS_OF_STEVEN)'], {matchBase: true}))
...但遗憾的是它不符合我的规则:
minimatch('./test', ['!*(rock|pop|steven/**)'], {matchBase: true}))
我的问题是: 我怎样才能隐藏除了rock+pop+steven+steven 的子目录之外的所有东西?
目录结构的更好概述:
test
|-rock
|--martin
|--steven
|---coolmusik
|----newmusic
|-pop
|--martin
|--steven
|---mysubdir
|---anothersubdir
另外:如果 minimatch 无法处理这个问题,上面规则的常规正则表达式会是什么样子?