# Search string in batch file



## difaz23 (Jun 27, 2005)

This is probably an easy question for you guys but I am trying to search a string that I pass to my batch file for the term "failure" and perform an action if the text is found within that string. How can I accomplish this?


----------



## draceplace (Jun 8, 2001)

Here is an example of installing a new version of winzip. each time I install I post the computer name, time/date and version to ziplog.csv. The first 'findstr' writes the first line(record) it finds to wz.txt if it finds the computer name. If not go install. If computer name is found I check the version in the log (not in wz.txt)...delete wz.txt at the end of the routine, it is basically at temp file written to C:\.

:Check_Install_Log
findstr %computername% \\servername\Downloads\WinZip9.1\ziplog.csv>wz.txt
if errorlevel 1 GOTO Install
echo 9.0 already installed

:Check_Version
findstr "WINZIP9sr1" wz.txt
if errorlevel 1 GOTO Install

echo SR1 already installed


----------



## difaz23 (Jun 27, 2005)

Great, thanks. That helped me to get started.


----------



## draceplace (Jun 8, 2001)

I just reread my comment and found an error...

"If computer name is found I check the version in the log (not in wz.txt)..."

I do actually look in wz.txt for the version. Because the first 'find' writes that complete record in there (from the log).

Later in this routine if ever thing is successfull I write to the log then if I try to install again this routine can kick you out.


----------

