user3438791
user3438791

Reputation: 89

Find multiple string matches from the original string batch script

I currently have a list of files in a folder that i need to iterate through and exclude the non production files that matches the pattern. how do i search for multiple strings in a batch command?

for example i have files as

from the list above i need to exclude every file that has the word "dev", QA "Stg" and generate a list of files without them - which is

The problem is - i am not able to find any batch command that can do a grep equivalent for multiple strings. FindStr does it only for one string and hence i am not able to get that working. here is code that i have

set i=0
for /F "delims=" %%a in ('dir /B /A /S Path *.txt') do (
   set /A i+=1
rem put the file names in array
   set list[!i!]=%%~na
rem try to find the file names 
echo %%~na|find "dev" or "qa" or "stg" >nul
if errorlevel 1 (echo notfound) else (echo found %%~na )
  
)

Upvotes: 0

Views: 971

Answers (1)

user3438791
user3438791

Reputation: 89

Thank you for all the response. I was able to do it below way

echo %%~na|findstr /i /v "dev QA Stg" >nul
if errorlevel 1 (echo not found %%~na) else (echo %%~na>>newfile.txt)

Upvotes: 1

Related Questions