【问题标题】:Find String inside Files and generate report在文件中查找字符串并生成报告
【发布时间】:2015-03-04 06:50:03
【问题描述】:

我需要在我的系统中搜索一个特定的字符串。

我会提供一个文件路径

程序应在该文件路径中搜索一个预定义的字符串,该字符串可能包含多个文件夹和具有不同扩展名的文件。 然后它应该生成一个 .txt 报告,其中包含文件名及其包含该字符串的文件路径(如果可能,偶数行号)

我找到了similar article here,但它只搜索包含文件的定义路径。它不会递归地遍历位于该路径内的文件夹并再次搜索它。

【问题讨论】:

  • 我参考了链接中提到的代码。我使用了它,但它不搜索路径内的文件夹;休息很好

标签: windows vba powershell search vbscript


【解决方案1】:
findstr /s /m /l /c:"searchString" "c:\somewhere\*" > outputFile.txt

【讨论】:

    【解决方案2】:

    这是一个 powershell 解决方案:

    $filePath = "c:\"
    $searchString = "test"
    $outputFilePath = "c:\searchResults.txt"
    
    Get-ChildItem $filePath -Recurse | Select-String $searchString | select Path, LineNumber | Out-File $outputFilePath -Force
    

    【讨论】:

      猜你喜欢
      • 2013-06-07
      • 2014-06-22
      • 1970-01-01
      • 2021-09-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多