topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Thursday April 18, 2024, 6:59 pm
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: IDEA: Add/Update Increment to File Extension  (Read 6557 times)

AzureToad

  • Charter Member
  • Joined in 2006
  • ***
  • Posts: 95
    • View Profile
    • Read more about this member.
    • Donate to Member
IDEA: Add/Update Increment to File Extension
« on: October 27, 2009, 03:32 PM »
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

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,736
    • View Profile
    • Donate to Member
Re: IDEA: Add/Update Increment to File Extension
« Reply #1 on: October 27, 2009, 03:56 PM »
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.
« Last Edit: October 27, 2009, 03:59 PM by MilesAhead »

AzureToad

  • Charter Member
  • Joined in 2006
  • ***
  • Posts: 95
    • View Profile
    • Read more about this member.
    • Donate to Member
Re: IDEA: Add/Update Increment to File Extension
« Reply #2 on: October 27, 2009, 05:36 PM »
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.

  • 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

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,736
    • View Profile
    • Donate to Member
Re: IDEA: Add/Update Increment to File Extension
« Reply #3 on: October 27, 2009, 09:08 PM »
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

  • Honorary Member
  • Joined in 2009
  • **
  • Posts: 118
    • View Profile
    • Donate to Member
Re: IDEA: Add/Update Increment to File Extension
« Reply #4 on: October 28, 2009, 09:13 AM »
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...
_____________________________________________
J.

AzureToad

  • Charter Member
  • Joined in 2006
  • ***
  • Posts: 95
    • View Profile
    • Read more about this member.
    • Donate to Member
Re: IDEA: Add/Update Increment to File Extension
« Reply #5 on: October 28, 2009, 11:07 AM »
 :Thmbsup:

Looks like it's going to do the trick!  Thank you so much!

Can I ask, what language did you write it in?

awopbamboo

  • Honorary Member
  • Joined in 2009
  • **
  • Posts: 118
    • View Profile
    • Donate to Member
Re: IDEA: Add/Update Increment to File Extension
« Reply #6 on: October 28, 2009, 11:15 AM »
Pascal, freepascal.

http://www.freepascal.org/

I usually use, Delphi or FreePascal/Lazarus

_____________________________________________
J.

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,736
    • View Profile
    • Donate to Member
Re: IDEA: Add/Update Increment to File Extension
« Reply #7 on: October 31, 2009, 05:07 PM »
This may not fit the spec. but it coincidentally popped up.  Somebody might like an automated backup software that's free for personal use:

http://www.docshield.com/

I have a feeling that it works by being notified by the file system. Since I turn that stuff off as much as possible I haven't tried it myself. But someone who does lots of documents may find it useful.  For my small amount of source code I just use FreeCommander to sync folders manually.
« Last Edit: October 31, 2009, 05:17 PM by MilesAhead »