I’m currently doing a findstr from a set of log files called link.2011*.log using a batch file with a SET command but am having trouble trying to echo the log file.
Code:
...
set /P log=.\DIR\%DEV%\link.2011*.log
findstr /L /C:"matrix" %log%
if errorlevel 1 (
echo %DEV% --- matrix not found >> .\output.txt
) else (
echo %DEV% --- matrix found %log% >> .\output.txt
:END
The output.txt does print the %dev% variable but the %log% variable outputs the whole string .\DIR\%DEV%\link.2011*.log
I would like the code to output the actual link.2011xxxxxxxx.log rather than the string.
Any help is appreciated.
Thanks.
If you use the
/Mswitch with theFINDSTRcommand, the output will only display the name(s) of the file(s) where the match has taken place:If you want the output to be exactly like in your example script, you could try the following approach:
That is, the
FINDSTRcommand searches for the string and outputs the list of files into a temporary file. If the search was successful, thematrix foundmessage gets printed to.\output.txt, otherwise thematrix not foundone does.Afterwards, the contents of
.\tmpoutput.txtis appended tooutput.txt. (You can have no worries about this step being done in case there was no match, because in that case the temporary file will be empty, so it will not affect the contents ofoutput.txt.)