Home > Blockchain >  If a value in a text file less than X do the following
If a value in a text file less than X do the following

Time:11-26

There's a file called "Settings.txt", this file contains a lot of lines including the following variable line:

X 100

The number in this line is the variable part, "X" is a fixed text.

What I need is to check if that number is (less than 100) OR (equal or greater than 100) then based on the result > goto A or B.

The script could be something like:

IF >> "X 100" in "D:\Settings.txt" GEQ 100 goto A else goto B
:A
@echo the value is equal or greater than 100
pause & goto continue
:B
@echo the value is less than 100
pause
:continue
#the rest of the script

CodePudding user response:

A mechanism to read from the Settings.txt file is needed to get the number.

@ECHO OFF
FOR /F "tokens=1,2" %%A IN ('findstr.exe /B "X [:digit:] " "Settings.txt"') DO (SET "NUM=%%~B")
ECHO NUM is set to %NUM%
IF  %NUM% GEQ 100 (GOTO ALABEL) ELSE (GOTO BLABEL)
:ALABEL
    ECHO Do greater than or equal stuff
    GOTO TheEnd
:BLABEL
    ECHO Do less than stuff
    GOTO TheEnd
:TheEnd
EXIT /B 0
  • Related