How to search for files in different directories recursively in VSCode?
Answer a question
Visual Studio Code (as of version 1.41.1) is obviously very limited in regard of its file search. It seems to only allow to either search in folders recursively or in specific files, but it doesn't allow both.
Search in folders recursively
path/to/folder/searches in any directories within subpaths matchingpath/to/folderincluding all subdirectories with no restriction in file names../path/to/folder/, ./path/to/another/foldersearches in the directories with the pathspath/to/folderandpath/to/another/folderrelative to the project's root directory.
Search in files
foo.barsearches in all files namedfoo.bar.*.foo, *.barsearches in all files with the extensionsfooorbar../path/to/folder/*/*.foosearches in all files with the extensionfoothat lie in a direct subdirectory ofpath/to/folder/relative to the project's root directory.
Search in folders recursively and filter by file name
So, how to combine these two searches, i.e. filter the search by file names but search in specific directories with all their subdirectories?
In other editors like Eclipse you normally have two different fields for file names and folders, making it easy to specify them individually and avoid having to repeat yourself for multiple folders and file names. Therefore I have already created an enhancement request in the VSCode bug tracker asking to add a separate field for the folder.
Answers
In my testing, using the globstar does provide the functionality you desire.
https://github.com/isaacs/node-glob#glob-primer:
**If a "globstar" is alone in a path portion, then it matches zero or more directories and subdirectories searching for matches. It does not crawl symlinked directories.
So that ./path/to/folder/**/*.foo for example searches within all subdirectories of folder no matter how deep within files with the foo extension.
Same at https://code.visualstudio.com/docs/editor/codebasics#_advanced-search-options:
**to match any number of path segments, including none
更多推荐
所有评论(0)