I need to save previous versions of reports from a batch process. I'd like to call a script or program from a command line BEFORE running the batch process to rename files with the existing name, bumping a "version" number.
I'd end up with
filename.ext (current version)
filename.ext002 (2 copies back)
The pseudo-code would look something like this:
if exists filename.ext%MaxVal
set /A StartVal=%MaxVal-1
for /L %Val in (%StartVal,-1,1) do (
if exist filename.ext%Val do (
set /A NxtVal=%Val+1
ren filename.ext%Val filename.ext%NxtVal
if exist filename.ext
ren filename.ext filename.ext001
I'd like to be able to set the maximum number of copies to keep in an environment variable and pass the file name as a parameter on a command line. I'd also like the values to be 3 digits long, padded with 0's when necessary.