0

I need help for Find value from text, then compare match in range list condition goto

File 1.txt contains multiple line:

[Software]
App=3

I write batch but stuck

@ECHO ON
FOR /F "TOKENS=2 DELIMS== " %%I IN ('FINDSTR App D:\1.txt') DO
    SET App=%%I
    IF "%App%"=="1" GOTO :1
    IF "%App%"=="2" GOTO :2
    IF "%App%"=="3" GOTO :3

:NOTINRANGE
ECHO Not Found
Exit

:1
ECHO %App%
EXIT

:2
ECHO %App%
EXIT

:3
ECHO %App%
EXIT

If %App% value is not in range [1,2,3], i don't know how to write condition

2 Answers 2

2

The set command must be on the same physical line as the do

Sign up to request clarification or add additional context in comments.

Comments

0

In your particular example you could do this a couple of different ways because the result of your command is the same as your label names.

You could just execute the goto command directly with the result of FOR variable.

FOR /F "TOKENS=2 DELIMS==" %%I IN ('FINDSTR App D:\1.txt') DO goto %%I

If you really need to test the range of the value you could still accomplish this without all the extra IF comparisons. This assume your app value would never be zero or less than 0.

FOR /F "TOKENS=2 DELIMS==" %%I IN ('FINDSTR App D:\1.txt') DO IF %%I LEQ 3 GOTO %%I

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.