Batch file include external file for variables

后端 未结 9 1055
遥遥无期
遥遥无期 2020-12-04 08:20

I have a batch file and I want to include an external file containing some variables (say configuration variables). Is it possible?

9条回答
  •  攒了一身酷
    2020-12-04 09:05

    :: savevars.bat
    :: Use $ to prefix any important variable to save it for future runs.
    
    @ECHO OFF
    SETLOCAL
    
    REM Load variables
    IF EXIST config.txt FOR /F "delims=" %%A IN (config.txt) DO SET "%%A"
    
    REM Change variables
    IF NOT DEFINED $RunCount (
        SET $RunCount=1
    ) ELSE SET /A $RunCount+=1
    
    REM Display variables
    SET $
    
    REM Save variables
    SET $>config.txt
    
    ENDLOCAL
    PAUSE
    EXIT /B
    

    Output:

    $RunCount=1

    $RunCount=2

    $RunCount=3

    The technique outlined above can also be used to share variables among multiple batch files.

    Source: http://www.incodesystems.com/products/batchfi1.htm

提交回复
热议问题