vscode中如何排除除一个文件夹之外的所有文件夹?

leo*_*eon 16 visual-studio-code

\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 target\n    \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 W350\n    \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 W400\n    \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 W600\n    \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 W600_HW_V2\n    \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 W600_KT_HW_V2\n    \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 W600_KT_HW_V2_neutral\n    \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 W600_TK\n    \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 W650\n    \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 W650_HW_V2\n    \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 W750\n
Run Code Online (Sandbox Code Playgroud)\n\n

我想排除除W600_KT_HW_V2. 然后 VSCode 应显示此树:

\n\n
\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 target\n    \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 W600_KT_HW_V2\n
Run Code Online (Sandbox Code Playgroud)\n\n

我应该怎么办?

\n

Mar*_*ark 11

一般来说,你可以这样做:

"files.exclude": {
  //  "**/node_modules": true,

  "**/[^1]*": true,    // all you need in your example
  "**/1[^2]*": true,
  "**/12[^3]*": true
},
Run Code Online (Sandbox Code Playgroud)

就您而言,只"**/[^1]*": true,需要第一个。如果您也想排除类似的文件夹,则将使用附加行1abc。您的深度取决于文件夹名称的相似度。但您没有详细说明您的用例有多复杂。

但你看到了这个模式。Vscode 不支持!否定,files.exclude因此您必须排除除您想要的表单之外的所有内容[^x]


更新文件结构后,它看起来像这样:

"files.exclude": {
  "**/[^W]*": true,
  "**/W[^6]*": true,
  "**/W6[^0]*": true,

  "**/W600": true,         // the only one I had to "hardcode"
  "**/W600_[^K]*": true,
  "**/W600_KT_HW_V2_*": true
}
Run Code Online (Sandbox Code Playgroud)

考虑到您想要的唯一文件夹与要排除的文件夹有多相似,这还不算太糟糕。您可以在两个示例中看到一般模式 - 在之前排除类似的文件夹后,我能够消除一些中间体。


另请参阅如何在 Visual Studio Code 中排除边栏中除某些文件之外的所有文件?用于使用文件扩展名执行此操作。