Skip to content

Instantly share code, notes, and snippets.

@dadhi
Created June 17, 2014 06:14
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dadhi/1680320d9bf67d1ae071 to your computer and use it in GitHub Desktop.
Save dadhi/1680320d9bf67d1ae071 to your computer and use it in GitHub Desktop.
Batch script for persistent counter. Could be used for implementing state machine or suffixing backup files, etc. Uses "count file" to store counter between script executions.
@echo off
if [%1]==[] (echo error: Please specify countfile as command line argument. Could be count.txt or similar. && exit /B 1)
set COUNTFILE=%1
(set /P COUNT=<%COUNTFILE%)2>nul || set COUNT=0
set /A COUNT+=1
echo:%COUNT%>%COUNTFILE%
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment