How do you search in Visual Studio all files with certain extension that do NOT contain a specific string? Find in Files feature in visual studio ( VS 2008 or VS 2010 or VS 2012) has regex option but I did not see a way to find files that do not contain a string. I need to find in a project folder with thousands of files which aspx.cs files do not contain the string 'security'. I found some solutions no for windows platform, and was wondering how to do this on a windows machine and ideally without paying for an application? I also found another old posts on stackoverflow with wrong answers, and also used windows grep app and it did not work: Visual studio Find files that does NOT contain X
The solution also applies to this post: How to use Notepad++ to find files in a directory that do not contain string : https://superuser.com/questions/110350/how-to-use-notepad-to-find-files-in-a-directory-that-do-not-contain-string :
@Peter McEvoy: good catch! @jerone pls unaccept this answer as it's wrong... – jeroenh. this solution does not work. It will return false positives
The new experience is available by searching for “Find in Files” or “Replace in Files” in Visual Studio search (Ctrl+Q by default). You can also get to these commands with Ctrl+Shift+F and Ctrl+Shift+H respectively.
Visual Studio 17.2 Preview 3 introduces a brand-new All-In-One search experience that merges the existing VS Search (Ctrl + Q) and Go To (Ctrl + T) to allow you to search both your code and Visual Studio features quicker and easier than ever, all in the same place.
Ctrl+Q, Ctrl+M for Visual Studio menus, options, components, and templates.
I finally found solution to find all files with certain extension that do NOT contain a specific string, I was looking for a solution to this for a long time, and it works great and is free. Hope this helps others who are trying to do the same.
GOTO EndComment
1st Change source, destination, extension and string to your needs.
2nd Remove ECHO from line 19 (If you want to make a copy of those
specific files that contain the string to destination folder)
3rd Save this piece of code on a file file with extension .cmd
and run it to get results (just double click on file).
:EndComment
@echo off
setlocal
set source=c:\Users\youruseraccount\Documents\Visual Studio 2012\PathofProject\
set destination=c:\foundFilesWithoutString\
set extension=*.aspx.cs
set string=Security
for /f "tokens=*" %%G in ('dir /s "%source%\%extension%" /a:-d /b') do (
find /c /i "%string%" "%%G" > NUL || (
ECHO copy "%%G" "%destination%"
)
)
pause
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With