visual-studio-code - 如何在VSCode中递归搜索不同目录下的文件?

标签 visual-studio-code full-text-search

Visual Studio Code(自版本 1.41.1 起)在文件搜索方面显然非常有限。它似乎只允许在文件夹中递归搜索或在特定文件中搜索,但不允许两者兼而有之。

递归搜索文件夹

  • path/to/folder/ 搜索与 path/to/folder 匹配的子路径内的任何目录,包括所有子目录,且文件名不受限制。
  • ./path/to/folder/, ./path/to/another/folder 在路径为 path/to/folder 的目录中搜索>path/to/another/folder 相对于项目根目录。

在文件中搜索

  • foo.bar 搜索名为 foo.bar 的所有文件。
  • *.foo, *.bar 搜索所有扩展名为 foobar 的文件。
  • ./path/to/folder/*/*.foo 搜索位于 path/直接子目录中的所有扩展名为 foo 的文件to/folder/ 相对于项目根目录。

递归搜索文件夹并按文件名过滤

那么,如何将这两种搜索结合起来,即按文件名过滤搜索,但在特定目录及其所有子目录中搜索?

在 Eclipse 等其他编辑器中,通常有两个不同的文件名和文件夹字段,这样可以轻松单独指定它们,并避免为多个文件夹和文件名重复操作。因此我已经创建了一个 enhancement request in the VSCode bug tracker asking to add a separate field for the folder .

最佳答案

在我的测试中,使用 globstar 确实提供了您想要的功能。

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.

这样./path/to/folder/**/*.foo例如在 folder 的所有子目录中搜索无论 foo 在文件中有多深扩展名。

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

** to match any number of path segments, including none

关于visual-studio-code - 如何在VSCode中递归搜索不同目录下的文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60053690/

相关文章:

visual-studio-code - Visual Studio Code 向后滚动缓冲区

nhibernate - PostgreSQL 全文搜索与 NHibernate.Search 通过 Lucene.Net

postgresql - 索引数组以进行全文搜索

search - 使用 lucene 进行多语言搜索

flutter - 使用 VS Code 发布 Flutter 的应用程序

python - 如何为多个 python 项目设置 VS Code

macos - 在Visual Studio Code中仅缩放文本

javascript - visual studio 代码 intellisense 不适用于 dojo amd 代码

sql-server - 全文搜索 "Contains"比 "Like %"慢

sql-server - 告诉我 SQL Server 全文搜索器疯了,不是我疯了