Home > other >  how to limit search to certain folder AND certain file types (more than one) in visual studio code?
how to limit search to certain folder AND certain file types (more than one) in visual studio code?

Time:03-10

consider the following files and folders structure:

  head.html
  folder1
      1.css (this file is inside "folder1")
      1.html
      1.php
  folder2
      1.css
      1.html
      1.php
      subfolder2 (this is a subfolder inside "folder2")
          1.css
          1.html
          1.php
          deepsub2 (a folder inside "subfolder2" that is inside "folder2")
              1.css
              1.html
              1.php

to clarify the structure:

  • "folder1", "folder2", "subfolder2" and "deepsub2" are folders. all the rest are files.
  • "1.css", "1.html" and "1.php" under that appear under a folder, for example "folder1" are inside that folder.
  • "head.html" is in the root folder.
  • "subfolder2" is a folder inside "folder2" and "deepsub2" is a folder inside "subfolder2".

What i'm trying to do is search the word "viewport" in "folder2" and anything beneath it (including its subfolders), which means I don't want search in other folders (folder1 for example) or the root (head.html for example)

I also want to limit the search for file types: .html and .css

I DON'T want to specifically exclude .php as a file type because consider that sometimes I don't know what other file types there are in the structure and they can be t0o many to exclude, so I want to only to use a list of file types to include rather.

after reading the docs: https://code.visualstudio.com/docs/editor/codebasics#_advanced-search-options

the best I could come up with is using the following in the "files to include" input:

./folder2/**/*.css,./folder2/**/*.html

but it doesn't seem efficiant enough because i'm using the "folder2" path part for every file type. is there a better way?

I'm using VScode Version: 1.65.0 by the way

CodePudding user response:

This should work:

./folder2/**/*.{css,html} NO spaces in the {...} extensions or it won't work

from https://code.visualstudio.com/docs/editor/codebasics#_advanced-search-options:

{} to group conditions (for example {**/*.html,**/*.txt} matches all HTML and text files)

  • Related