7

如何在 Visual Studio 中搜索具有特定扩展名但不包含特定字符串的所有文件?Visual Studio 中的“在文件中查找”功能(VS 2008 或 VS 2010 或 VS 2012)具有正则表达式选项,但我没有看到查找不包含字符串的文件的方法。我需要在包含数千个文件的项目文件夹中找到 aspx.cs 文件不包含字符串“安全”。我发现一些解决方案不适用于 Windows 平台,并且想知道如何在 Windows 机器上执行此操作,理想情况下无需支付应用程序费用?我还在stackoverflow上发现了另一个旧帖子,答案有误,还使用了windows grep app,但它不起作用: Visual Studio Find files that does not contain X

该解决方案也适用于这篇文章:如何使用 Notepad++ 在不包含字符串的目录中查找文件: https ://superuser.com/questions/110350/how-to-use-notepad-to-find-files-在-a-directory-that-do-not-contain-string 中

@Peter McEvoy:好收获!@jerone 请不要接受这个答案,因为它是错误的...... – jeroenh。此解决方案不起作用。它将返回误报

4

2 回答 2

14

我终于找到了找到具有特定扩展名但不包含特定字符串的所有文件的解决方案,我一直在寻找解决方案,它工作得很好并且是免费的。希望这可以帮助其他正在尝试做同样事情的人。

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
于 2013-04-26T15:47:50.700 回答
-2

Visual Studio 代码有一个扩展,用于查找不包含特定字符串的文件反向搜索

于 2019-10-22T04:53:11.067 回答