Batch File to check value of variable

February 1, 2012 at 08:56:46
Specs: Windows XP
Using this batch file that I found here:
@echo off
setLocal EnableDelayedExpansion

for /f "tokens=* delims= " %%a in (sessopen.log) do (
set var=%%a
echo !var!

I get this result from my file I'm looking at:

02/01/12 10:00:00 AM Session 3 is closed

I want to compare the last word of that file. The word will either be Open or Closed. Everything else isn't necessary for me to look at. I'm just wanting to check either Open or Closed.

So above batch file runs then,

If last word is Open goto something (i can handle)
if last word is Closed goto something

How do I do that?

The echo command in the batch file will not be used, just in there for testing atm.

Thanks in advance.

See More: Batch File to check value of variable

Report •

February 1, 2012 at 09:20:04
@echo off
for /F "tokens=7" %%a in (sessopen.log) do set var=%%a
if /I "%var%"=="closed" (goto :CLOSED) else (goto :OPEN)
goto :EOF

goto :EOF

goto :EOF

Report •

February 1, 2012 at 09:34:33
Thanks for the help.

Report •
Related Solutions

Ask Question