How can I exclude these folders and files when searching a very large Visual Studio project?

610 Views Asked by At

I am trying to search a very large application with hundreds of folders and thousands of files using the Visual Studio "Find in files" feature. I want to search all C# files (*.cs) excluding:

  • View*.cs
  • *\UnitTests\*.cs
  • *\Archive\*.cs

I found How do I tell Visual Studio to exclude folders from the Find in Files? and responses, but due to the size of the application, adding each folder is not workable, nor is unchecking "Search subfolders":

New folders are added frequently so I'd rather have an exclude list instead of an include list so I don't miss anything.

Is there a "Not" operator syntax for file types? I tried ^, !, and | to no avail.

1

There are 1 best solutions below

4
Kundan On

Did you try Ctrl + Shift + F which will give you following option.

In the search window you can select which folders to include in the search.

screenshot

Alternatively if you have Git Bash installed and if your project is a git repo then easiest way is to use following command. I tested it with my project and it works fine with sub folders as well.

git ls-files -- '*.cs' ':!:*Test*.cs'

This will include *.cs file but exclude anything like *Test*.cs. You can change the pattern as per your requirement.