Skip to content

Instantly share code, notes, and snippets.

@MarioLiebisch
Created November 24, 2015 18:52
Show Gist options
  • Save MarioLiebisch/c92bd0123b445a406dfd to your computer and use it in GitHub Desktop.
Save MarioLiebisch/c92bd0123b445a406dfd to your computer and use it in GitHub Desktop.
Windows batch: Get the next free numbered file name
@echo off
REM Initialize the first/lowest number
set NUMBER=0
REM Jump point: return here if the current file exists
:LOOP
REM Leave the loop in case the file doesn't exist
if not exist backup-%NUMBER%.zip goto DONE
REM Increment the counter
set /a NUMBER+=1
REM Well, loop...
goto LOOP
REM Jump point: we're done
:DONE
REM Now do something with the "next free numbered file"
move backup.zipe backup-%NUMBER%.zip
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment