Complete Guide to Excluding Folders from File Explorer in Visual Studio Code

Nov 22, 2025 · Programming · 16 views · 7.8

Keywords: Visual Studio Code | file exclusion | files.exclude | workspace settings | glob patterns

Abstract: This article provides a comprehensive exploration of various methods to exclude folders from the file explorer in Visual Studio Code. By analyzing the limitations of jsconfig.json configuration, it focuses on the usage of files.exclude settings, including detailed steps for both GUI and code-based approaches. The article delves into glob pattern matching, differences between workspace and user settings, and the coordinated use of related settings like search.exclude and files.watcherExclude. Through complete code examples and configuration explanations, it helps developers effectively manage project file structures and enhance development efficiency.

Problem Background and Common Misconceptions

In the Visual Studio Code development environment, many developers encounter issues with unnecessary folders appearing in the file explorer. A typical scenario occurs in JavaScript projects where developers attempt to exclude the node_modules folder using a jsconfig.json file:

{
    "compilerOptions": {
        "target": "ES6"
    },
    "exclude": [
        "node_modules"
    ]
}

However, this configuration does not affect the file explorer's display behavior. The exclude option in jsconfig.json is primarily used by the TypeScript compiler to specify files and folders that should be ignored during compilation, not to control the IDE's file tree display.

Correct Solution: files.exclude Settings

Visual Studio Code provides dedicated files.exclude settings to control the display of files and folders in the file explorer. These settings use glob pattern matching to define file patterns that should be hidden.

GUI Configuration Method

For users who prefer graphical interface operations, configuration can be done through the following steps:

  1. Open settings: File → Preferences → Settings (Windows/Linux) or Code → Preferences → Settings (macOS)
  2. Select the Workspace Settings tab to make configurations apply only to the current project
  3. Type "exclude" in the search box to quickly locate relevant settings
  4. Click the "Add Pattern" button and enter the folder patterns to exclude

Code Configuration Method

For developers comfortable with directly editing configuration files, workspace settings can be accessed through:

Add the following configuration to the opened settings.json file:

{
    "files.exclude": {
        "**/.git": true,
        "**/.DS_Store": true,
        "**/node_modules": true,
        "dist": true,
        "build": true
    }
}

Glob Pattern Detailed Explanation

Visual Studio Code uses glob patterns for file matching. Understanding these patterns is crucial for effective configuration:

Related Exclusion Settings

Besides files.exclude, Visual Studio Code provides other related exclusion settings:

search.exclude

Controls files and folders to exclude from search functionality:

{
    "search.exclude": {
        "**/node_modules": true,
        "**/bower_components": true,
        "**/*.min.js": true
    }
}

This setting inherits all patterns from files.exclude by default but can include additional search-specific exclusion rules.

files.watcherExclude

Controls file paths that should be ignored by the file watcher, significantly improving performance for large projects:

{
    "files.watcherExclude": {
        "**/.git/objects/**": true,
        "**/.git/subtree-cache/**": true,
        "**/node_modules/**": true
    }
}

Workspace Settings vs User Settings

Understanding the difference between the two setting scopes is crucial for proper configuration:

For project-specific exclusion rules, using workspace settings is recommended, ensuring configurations are version-controlled with the project.

Practical Application Scenarios

Here are some common exclusion configuration scenarios:

Frontend Project Configuration

{
    "files.exclude": {
        "**/node_modules": true,
        "**/dist": true,
        "**/build": true,
        "**/.cache": true,
        "**/coverage": true
    }
}

Python Project Configuration

{
    "files.exclude": {
        "**/__pycache__": true,
        "**/.pytest_cache": true,
        "**/*.pyc": true,
        "**/.venv": true
    }
}

Troubleshooting

If exclusion settings don't take effect, check the following points:

  1. Confirm you're using workspace settings instead of user settings
  2. Verify glob patterns are correctly written
  3. Restart Visual Studio Code for certain settings to take effect
  4. Check if other extensions are interfering with file display

Performance Optimization Considerations

Proper use of exclusion settings not only improves development experience but also enhances IDE performance:

By properly configuring Visual Studio Code's exclusion settings, developers can create cleaner, more efficient development environments, focusing on truly important project files.

Copyright Notice: All rights in this article are reserved by the operators of DevGex. Reasonable sharing and citation are welcome; any reproduction, excerpting, or re-publication without prior permission is prohibited.