24

I am trying to find a line of code to all my files with a specific file name criteria. I am trying to take advantage the Advanced Search of the Visual Studio Code by putting a wildcard in the files to include field of the search. But I wasn't able to achieve that. I tried to use asterisk (*) symbol, but I think the Visual Studio Code does not accept that. So I tried to search the internet and found this solution by using the .+?; however, it still does nothing.

Search Keyword: ICustomMatColumn

files to include: (wildcard)viewmodel.ts

enter image description here

Rich
  • 3,928
  • 4
  • 37
  • 66

2 Answers2

23

Apparently, Visual Studio Code supports glob syntax which is really great. To achieve the desired result in the question, you just need to follow this format:

./**/*< partialFileName >

Example

Folder Structure:

|-- app
    |-- users
        |-- list.ts|html|css|viewmodel
        |-- form.ts|html|css|viewmodel
    |-- cars
        |-- list.ts|html|css|viewmodel
        |-- form.ts|html|css|viewmodel
        |-- configurator.ts|html|css|viewmodel
    |-- app.component.ts|html|css
    |-- app.module.ts
    |-- user.service.ts
    |-- car.service.ts
|-- index.html
|-- main.ts
|-- style.css

Let's Assume that every ViewModel file has this word/code/string ICustomMatColumn

Search Keyword: ICustomMatColumn

Files to Include: ./**/*ViewModel.ts

Search Result:

|-- app
    |-- users
        |-- list.ts|viewmodel
        |-- form.ts|viewmodel
    |-- cars
        |-- list.ts|viewmodel
        |-- form.ts|viewmodel
        |-- configurator.ts|viewmodel

It will strictly include only the files with the partialFileName that you entered in the files to include field

Rich
  • 3,928
  • 4
  • 37
  • 66
  • Note: You can add this after a path like: "./folderA/folderB/**/*ViewModel.ts" Self-explanatory, but maybe the short example above is not understandable for everyone. ;) – user706420 Aug 05 '22 at 08:33
  • 1
    Thanks. For `glob syntax` see => https://mincong.io/2019/04/16/glob-expression-understanding/ – A. Morel Sep 16 '22 at 12:55
  • Extending on this answer: I wanted to search in a specific folder, and all of it's subfolders - limited by file extension. some-folder/**/*.java – eitama Mar 09 '23 at 12:58
7

So I found that the asterisk (*) works when you put in the files to include field the higher level folder name as the criteria

The format will be higherLevelFolderName*

Example:

Folder Structure:

|-- app
    |-- users
        |-- list.ts|html|css|viewmodel
        |-- form.ts|html|css|viewmodel
    |-- cars
        |-- list.ts|html|css|viewmodel
        |-- form.ts|html|css|viewmodel
        |-- configurator.ts|html|css|viewmodel
    |-- app.component.ts|html|css
    |-- app.module.ts
    |-- user.service.ts
    |-- car.service.ts
|-- index.html
|-- main.ts
|-- style.css

Let's Assume that every ViewModel file has this word/code/string ICustomMatColumn

Search Keyword: ICustomMatColumn

Files to Include: app*

Search Result:

|-- app
    |-- users
        |-- list.ts|viewmodel
        |-- form.ts|viewmodel
    |-- cars
        |-- list.ts|viewmodel
        |-- form.ts|viewmodel
        |-- configurator.ts|viewmodel

But the CONS of this solution is in case your search criteria is present in the other file, it will be included to the search result.

Rich
  • 3,928
  • 4
  • 37
  • 66