Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I increment a value in a textfile using the regular Windows command-line?

I'd like to keep a "compile-counter" for one of my projects. I figured a quick and dirty way to do this would be to keep a text file with a plain number in it, and then simply call upon a small script to increment this each time I compile.

How would I go about doing this using the regular Windows command line?

I don't really feel like installing some extra shell to do this but if you have any other super simple suggestions that would accomplish just this, they're naturally appreciated as well.

like image 755
grapefrukt Avatar asked Sep 02 '08 22:09

grapefrukt


2 Answers

You can try a plain old batchfile.

@echo off
for /f " delims==" %%i in (counter.txt) do set /A temp_counter= %%i+1
echo %temp_counter% > counter.txt

assuming the count.bat and counter.txt are located in the same directory.

like image 152
crono Avatar answered Sep 22 '22 14:09

crono


It would be an new shell (but I think it is worth it), but from PowerShell it would be

[int](get-content counter.txt) + 1 | out-file counter.txt
like image 28
Steven Murawski Avatar answered Sep 20 '22 14:09

Steven Murawski