How to increment variable under DOS?

前端 未结 9 1653
清酒与你
清酒与你 2021-02-06 21:36

I\'ve spent the past 3hrs trying to work this out but just couldn\'t find a solution. Here\'s my batch script:

if NOT Exist Counter.txt GOTO START
Type c:\\count         


        
9条回答
  •  星月不相逢
    2021-02-06 22:14

    None of these seemed to work for me:

    @ECHO OFF
    
    REM 1. Initialize our counter
    SET /A "c=0"
    
    REM Iterate through a dummy list. 
    REM Notice how the counter is used: "CALL ECHO %%c%%" 
    FOR /L %%i in (10,1,20) DO (
    
      REM 2. Increment counter
      SET /A "c+=1"
    
      REM 3. Print our counter "%c%" and some dummy data "%%i"
      CALL ECHO Line %%c%%: - Data: %%i
    )
    

    The answer was extracted from: https://www.tutorialspoint.com/batch_script/batch_script_arrays.htm (Section: Length of an Array)

    Result:

    Line 1: - Data: 10
    Line 2: - Data: 11
    Line 3: - Data: 12
    Line 4: - Data: 13
    Line 5: - Data: 14
    Line 6: - Data: 15
    Line 7: - Data: 16
    Line 8: - Data: 17
    Line 9: - Data: 18
    Line 10: - Data: 19
    Line 11: - Data: 20
    

提交回复
热议问题