computing
  • 0

How To Increment Numbers In a Batch File

  • 0

I am trying to create a batch file that will increment a build number.
For instance, the batch file will read
“Version 1.2.xxx:”
(xxx will be the current build number)
After the batch file runs, it should increment the last 3 digits.
Example:
If the batch file reads:
Version 1.2.111
After it runs, it should read:
Version 1.2.112
I can create a batch file that will search for an specific string but after it runs the first time I have to change the script again to math the string.

I appreciate any help.

Share

0 Answers

  1. Will this work? It’s as simple as it gets…

    @ECHO OFF

    SET /p CurrentBuild=<CurrentBuild.txt
    SET /a NewBuild=%CurrentBuild%+1
    ECHO Build 123.456.%NewBuild%
    ECHO %NewBuild%>CurrentBuild.txt
    PAUSE

    It requires a text document with the build you are currently at in it.

    If your current build is 111, write that in a text document and save it as Current Build.txt

    EDIT:

    Here, I’ve improved it for you. Now it will run a one time set up, and make the file hidden and read only. Simple yet again, Let me know if it fits your needs.
    @ECHO OFF

    IF EXIST CurrentBuild.txt GOTO Start
    ECHO What is the current build?
    SET /p Build=””
    ECHO %Build%>CurrentBuild.txt
    ATTRIB +R +H CurrentBuild.txt

    :Start

    CLS
    SET /p CurrentBuild=<CurrentBuild.txt
    SET /a NewBuild=%CurrentBuild%+1
    ECHO Build 123.456.%NewBuild%
    ATTRIB -R -H CurrentBuild.txt
    ECHO %NewBuild%>CurrentBuild.txt
    ATTRIB +R +H CurrentBuild.txt
    PAUSE
    EXIT

    • 0