Batch script math (Adding and subtracting in a batch script)

Posted by Dark Training on May 22, 2008 tags: | batch

Baed on search traffic, I notice that alot of people are looking for how to add and subtract using a batch script. This is actually really easy.

In the example below I am going to set a base number for the example and then add or increment up the value. You can copy the code below and save it as counting.bat

@echo off
set count=1
set /a count=%count%+1
echo %count%
set /a count=%count%+1
echo %count%
set /a count=%count%+10
echo %count%
set /a count=%count%-1
echo %count%
pause

The result is pretty clear. If you still need more information feel free to leave a message below and I can give a more detailed example.