我需要一種列出所有文件的方法不是包含已知文本。Visual studio查找不包含X的文件
該項目包含超過1000個文件,我只想要那些不包含一些文本的文件。
我想到了正則表達式,但它沒有這樣的功能。
任何人都知道解決方案嗎?
我需要一種列出所有文件的方法不是包含已知文本。Visual studio查找不包含X的文件
該項目包含超過1000個文件,我只想要那些不包含一些文本的文件。
我想到了正則表達式,但它沒有這樣的功能。
任何人都知道解決方案嗎?
從命令提示符:
@for /r %f in (FILE_SPECIFIER) do @find "YOUR_STRING" "%f" > nul || echo %f
例如:
C:\web-trunk\Views>@for /r %f in (*.cshtml) do @find "Layout" "%f" > nul || echo %f
C:\data\web-trunk\Views\Account\RegisterPartial.cshtml
C:\data\web-trunk\Views\Admin\SiteInspector.cshtml
C:\data\web-trunk\Views\CandidateProfile\View.cshtml
C:\data\web-trunk\Views\Common\ContactFooterForInfoEmails.cshtml
C:\data\web-trunk\Views\Common\ContactFooterForInfoPages.cshtml
C:\data\web-trunk\Views\Common\ContactFooterForSalesEmails.cshtml
C:\data\web-trunk\Views\Common\ContactFooterForSalesPages.cshtml
工程就像一陣微風,謝謝 – 2016-08-25 19:52:21
任何有關如何找到不包含特定文本的文件的想法,但也排除某些文件類型(除了包括某些文件類型)? – thecoolmacdude 2017-01-26 15:27:18
@thecoolmacdude也許你可以使用這個:https://superuser.com/a/383646/494173 – mbomb007 2017-12-20 16:54:59
您可以使用notepad++的Find in Files功能。
步驟:
這裏是循環得到文件列表(在.cs
文件搜索)(可優化):
private void GetFileNamesNotContainingWord(string filePath, string searchDirectoryPath, string notContainingFilePath)
{
string[] lines = File.ReadAllLines(filePath);
List<string> filesList = new List<string>();
foreach (string line in lines)
{
if (!line.StartsWith("\t"))
{
filesList.Add(line.Substring(0, line.LastIndexOf('(')).Trim());
}
}
List<string> notContainedFiles = new List<string>();
foreach (FileInfo file in new DirectoryInfo(searchDirectoryPath).GetFiles("*.cs", SearchOption.AllDirectories))
{
if (!filesList.Contains(file.FullName))
{
notContainedFiles.Add(file.FullName);
}
}
File.WriteAllLines(notContainingFilePath, notContainedFiles.ToArray());
}
這種方法對於Visual Studio也是可能的,不需要在這裏建議使用額外的工具。可以使用全局搜索來獲取項目的所有文件列表以及包含文本的文件列表。有趣的問題是:是否有一個內置函數幫助從第一個「減去」第二個列表? – 2011-05-06 10:11:26
更新:由於彼得McVoy指出,這種解決方案是行不通的。它將返回誤報(包含沒有要搜索的文本的行的文件也將被打印)。一個VS宏或者一個自定義的powershell腳本可能是最好的選擇。我稍後可能會重新訪問這個答案。
供參考,這是我的回答:
你可以在命令行上做到這一點:
findstr /S /V /M text_to_search_for *.cs
這將打印不包含文本中的所有文件名
使用找到或findstr從命令窗口('DOS b牛')。
這不是VS但Windows的grep有一個功能,讓你反轉匹配:http://www.wingrep.com/ – 2012-05-10 07:00:46