# Solved: batch programming: reading and writing from/to text file?



## sternkanz (Oct 3, 2008)

Hi,

I would like to have a text file that stores a number, lets say 2000. I want my batch script to grab the number from that file, and put it into a variable. The script will then do stuff with that variable and once it is finished, add 1 to it (don't know how easy that bit is). Then I want the script to write this number (2001) back into the text file, overwriting the old number.

So basically the contents of the text file would go from 2000, to 2001, to 2002, etc each time the batch file is run.

Would anyone be able to point in the right direction for this?

Any help is highly appreciated.


----------



## devil_himself (Apr 7, 2007)

```
@for /f %%a in (file.txt) do @set /a var=%%a+1
echo.%var%>file.txt
```


----------



## sternkanz (Oct 3, 2008)

Thanks! Once again you guys are awesome.


----------

