1.

Solve : Searching for a string within a text file?

Answer»

I am building a batch file that would only call another batchfile if a CERTAIN text string is found within a PARTICULAR text file: I was thinking I could use the IF, FINDSTR and CALL commands to build this but since my DOS knowledge is limited at BEST I am unsure of the syntax.



For example

Execute batch file "A"

IF FINDSTR /I "Database" file.txt CALL B.bat. ELSE CALL C.bat.


anyhelp would be appreciated..You can do:

Code: [SELECT]FINDSTR /I file.txt "Database" > NUL
if not errorlevel 1 (CALL B.bat) ELSE CALL C.bat
The command FIND/FINDSTR return an errorlevel equal to 0 when the string is found in the file.
The most of the commands return an errorlevel 0 when they are correctly executed.

The sentence:
IF ERRORLEVEL 5 command
would be equivalent to
IF ERRORLEVEL >= 5 command <-- you can't do this

so, if you negate:

IF NOT ERRORLEVEL 5 command
is equivalent to
IF ERRORLEVEL < 5 command

and ...

IF ERRORLEVEL 5 IF NOT ERRORLEVEL 6 command[/tt][/color]
is equivalent to
IF ERRORLEVEL == 5 commandThanks Carlos



Discussion

No Comment Found