Create a Batch file (.bat) to search an string through multiple files

9,802

From batch

START cmd.exe /k "Findstr -m "34444" *.*"

From command line

Findstr -m "34444" *.*"

also from powershell, create named batch file *.cmd extension containing following content. (remember to change the gci path 'your folder path'.

@PowerShell -ExecutionPolicy Bypass -noexit -Command Invoke-Expression $('$args=@(^&{$args} %*);'+[String]::Join(';',(Get-Content '%~f0') -notmatch '^^@PowerShell.*EOF$')) & goto :EOF
gci -path 'c:\your folder path\' -fi '*' | Select-String -patt "34444" | select Filename, LineNumber | Format-Table -a

call batch file *.cmd to run the powershell search.

Share:
9,802

Related videos on Youtube

Alvaro
Author by

Alvaro

Web developer. Mainly working with PHP (and CakePHP framework), CSS and jQuery.

Updated on September 18, 2022

Comments

  • Alvaro
    Alvaro over 1 year

    I am using Windows Server 2008 and I need to create a Batch file (.bat) to search for a given string in 20.000 to 30.000 files located all in one folder in the same level (without subfolders).

    I have been searching and reading around but I couldn't find anything to do it.

    Trying it with this without success:

    @echo off for /r "delims=|" %%i in (*) do  (    
        findstr /m /C:"34444" %%i
    
    )
    
    • Tim Radcliffe
      Tim Radcliffe over 10 years
      This should point you at the commandline tools you'd need to use, depending on what you're looking for it should only take one command, shouldn't need a batch file: superuser.com/questions/300815/…
    • Alvaro
      Alvaro over 10 years
      I have updated the question.