Searching for strings in specific folders in VS Code

When working on a large codebase, you may want to search for a string only within a specific folder rather than the entire workspace. Here's how to do targeted searches in VS Code.

Searching within a subfolder

Let's say you want to find all files containing the string "tippytap" only within this folder:

``` src/store/js/components/groups ```

But there are also folders like:

``` src/store/js/components/selectbox/groups ```

that you want to exclude from the search.

You can use a glob pattern in the VS Code search box to target just the folder you want:

``` /src/store/js/components/groups//*.jsx ```

This will search for "tippytap" in all .jsx files recursively under src/store/js/components/groups.

To try it out, enter the glob pattern above in the VS Code search box, then enter "tippytap" as the search term. It will only find matches within that one folder.

Searching in a subfolder while excluding other similar folders

Let's say you want to search in:

``` src/store/js/components/subgroups ```

But there are also folders like:

``` src/store/js/components/groups/subgroups src/global/js/groups/subgroups ```

that contain similar files you want to exclude.

You can use a negative lookahead in the glob pattern to exclude those folders:

``` /src/store/js/components/subgroups//*.jsx ```

This will search in src/store/js/components/subgroups while excluding any paths that contain /groups/subgroups after that.

Again, enter this glob pattern in the VS Code search box, then search for "tippytap" to test it out.

Summary

  • Use glob patterns in VS Code search to target specific folders
  • Exclude similar folders with negative lookaheads in the glob
  • This lets you narrow down search results when dealing with large codebases

Hope this helps explain how to search within specific folders in VS Code! Let me know if you have any other questions.