I need to write a windows batch script. Starting from a given directory, I need to check whether there is at least one occurrence of a given text in every file with a given file name.
E.g.: Starting with the directory C:\MyDir, I need to check this directory and all subdirectories for files with the name "MyFile.txt". Every file found must have at least one occurrence of the text "MyText".
What I have so far is this:
FOR /R C:\MyDir %%f in (MyFile.txt*) do (
FINDSTR /i /c:"MyText" %%~f
)
Problems:
- This would also match for files with the name MyFile.txtXXX
- It does only print occurrences but does not "return" whether such an occurrency is found. This code is inside a batch script which must exit with an error, if there is one file without such an occurrence.
MyFile.txt*? Can this be translated to "find all 'MyFile.txt' that does (not) contain 'MyText')" ?