有一個名為“ Settings.txt ”的檔案,該檔案包含很多行,包括以下變數行:
X 100
此行數字為可變部分,“X”為固定文本。
我需要的是檢查該數字是否(小于 100) 或 (等于或大于 100)然后根據結果>轉到 A 或 B。
腳本可能是這樣的:
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
uj5u.com熱心網友回復:
需要一種從Settings.txt檔案中讀取的機制來獲取數字。
@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
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/366971.html
