Chris
Chris

Reputation: 180

Excluding Top-Level Directories in VS Code Without Affecting Nested Directories with Same Name

I'm working with a project in Visual Studio Code that has a directory structure like this:

project-root
├── dirA
│   └── dirB
├── dirB
└── tests
    ├── dirA
    └── dirB

I want to exclude dirA and dirB at the top level from the Explorer view using files.exclude in my workspace settings, without excluding the nested dirA/dirB, tests/dirA, and tests/dirB.

Using patterns like "**/dirA": true and "**/dirB": true in files.exclude unfortunately also hides the nested directories since the glob patterns apply to all directories with those names at any depth.

Is there a way to specify exclusions strictly at the top level in VS Code, using files.exclude or another method, so that only the top-level dirA and dirB are hidden, but not their namesakes deeper in the structure?

Current Limitation

VS Code's glob pattern matching for files.exclude does not provide a way to distinguish between directories at different levels of the project structure. The patterns apply globally, affecting all directories that match the pattern regardless of their depth relative to the workspace root.

Attempted Solutions

Upvotes: 0

Views: 160

Answers (1)

starball
starball

Reputation: 50554

I don't think what you're looking for is possible (though I'd be happy to be wrong). You can get closer with ./dir{A,B}/[!d]*. But it will fail to exclude folders and files under ${workspaceFolder}/dir{A,B} that start with d.

For docs, see https://code.visualstudio.com/docs/editor/codebasics#_advanced-search-options and https://code.visualstudio.com/docs/editor/glob-patterns.

Upvotes: -1

Related Questions