2

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.

Lance U. Matthews
  • 13,224
  • 6
  • 36
  • 62
WingNut
  • 59
  • 5

1 Answers1

0

Did you try ctrl + shft + F which will give you following option.

in the search window you can select which folders to include in the search. Check this screenshot this might help.

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.

Kundan
  • 1,094
  • 7
  • 21
  • Yes, that is exactly what I am doing. However, there are hundreds of subfolders. I want to skip all the unit tests and view files that are in the subfolders without explicitly selecting the hundreds of folders I do want to search. If someone adds a new folder to a solution I have to know that and manually update my folder set to search. – WingNut Jan 29 '20 at 00:18
  • do you have git cli installed and is your project git repo? check the updated answer. – Kundan Jan 29 '20 at 08:48
  • No on git, using VSTS exclusively. – WingNut Jan 29 '20 at 17:07
  • you can still utilize the gibash functionality, just download a git bash and try `git init` command in your projects root directory and use above command to list the required files – Kundan Jan 29 '20 at 23:05