12
└── target
    ├── W350
    ├── W400
    ├── W600
    ├── W600_HW_V2
    ├── W600_KT_HW_V2
    ├── W600_KT_HW_V2_neutral
    ├── W600_TK
    ├── W650
    ├── W650_HW_V2
    └── W750

I want to exclude all folders except W600_KT_HW_V2. VSCode should then show this tree:

└── target
    └── W600_KT_HW_V2

What should I do?

leon
  • 123
  • 1
  • 6
  • Have you seen this? https://stackoverflow.com/a/33277809/9401556 – Mohamad Mousheimish Mar 06 '20 at 14:19
  • Have you considered doing `cd 123` before running `code .`? Or just running `code 123`? – Peter B Mar 06 '20 at 14:24
  • The above is just an example. The actual situation is much more complicated. I need to load the upper directory. I know use "**/abc", "**/def", “**/fed” ...., too cumbersome – leon Mar 06 '20 at 14:28

1 Answers1

8

In general, you could do this:

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

  "**/[^1]*": true,    // all you need in your example
  "**/1[^2]*": true,
  "**/12[^3]*": true
},

In your case, only the first "**/[^1]*": true, would be needed. The additional lines would be used if you had folders like 1abc that you also want excluded. How deep you go depends on the similarity of your folder names. But you don't give a lot of detail on how complicated your use case is.

But you see the pattern. Vscode doesn't support ! negation in files.exclude so you have to exclude everything but what you want with the [^x] form.


After you updated your file structure, it looks like this works:

"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
}

which isn't too bad considering how similar the only folder you want is to those to be excluded. You can see the general pattern in the two examples - I was able to eliminate a few of the intermediates after similar folders were excluded earlier.


Also see How to exclude all but certain files in the sidebar in Visual Studio Code? for doing this with file extensions.

Mark
  • 143,421
  • 24
  • 428
  • 436