ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

DonationCoder.com Software > Post New Requests Here

IDEA: Add/Update Increment to File Extension

(1/2) > >>

AzureToad:
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.ext001  (previous)
  filename.ext002  (2 copies back)
etc.

The pseudo-code would look something like this:

if  exists filename.ext%MaxVal
  delete 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.

Thanks!

MilesAhead:
Google "glindra"

It is a set of command line tools that emulate some of the VMS operating system file functions.  One of which was version numbers in filenames.  Say if you saved a text file named Readme.txt if it already existed the one on disk would be renamed Readme.txt;1  the lowest number being the most recent. You would end up with a chain ;2 ;3 ;4 etc..  VMS had a "purge" command where you could set how many old versions to keep as in
purge Readme.txt /keep=6

or whatever.

VMS did it automatically.  These utilities simulate the effect by renaming using WinAPI I would assume.

It's probably the easiest way esp. since these command line programs should be debugged already.

They are free and come with documentation.

AzureToad:
VMS.* AzureToad shudders.    ;D
Glindra looks interesting and appears to almost do what I'm looking for.
However, a couple things that make it look like it won't work:

When a Glindra program creates a file, it will first check to see if that filename already exists. If it does, it will look for any previous old versions of that file, and determine the highest version number that is in use for this file. It will then do a rename operation on the existing file (which did until this time not have any version number), and assign the next higher version number to it.
--- End quote ---


* The numbering scheme starts at one and increments.  Thus, the lowest number is the oldest version, the highest number is the most previous version.  Not quite what I'm looking for.
* I have to run a Glindra program to utilize file version numbers.  That would mean I'd have to copy the existing FILENAME.EXT to something, then use Glinda's COP command to copy the file over the top of itself so the current version (without a version number) would then be given the next higher version number.  It could be done, but it's convoluted
Great find, but I'm still looking.

MilesAhead:
In VMS it was the other way around.  Newest backup was ;1 I'm sure of that.  He must do it the way you document to cut down on operations.

Have you tried looking at actual version control systems?  There are some free ones out there. I don't know how complicated they are though.  There may be some simple enough to aid what you are doing.

If you haven't already you might check on SourceForge.net.  If you add the keyword 'win32' to searches you will get mostly Windows apps.

awopbamboo:
Hi

I put something together quickly, its rough, but it works.

You need to set environment variable MAXVAL to your max value.  And 1 parameter is expected, which is the filename i.e. filename.ext

Let me know if it works.

Executable attached...

Navigation

[0] Message Index

[#] Next page

Go to full version