Welcome Guest.   Make a donation to an author on the site October 31, 2014, 05:00:11 AM  *

Please login or register.
Or did you miss your validation email?


Login with username and password (forgot your password?)
Why not become a lifetime supporting member of the site with a one-time donation of any amount? Your donation entitles you to a ton of additional benefits, including access to exclusive discounts and downloads, the ability to enter monthly free software drawings, and a single non-expiring license key for all of our programs.


You must sign up here before you can post and access some areas of the site. Registration is totally free and confidential.
 
Your Support Funds this Site: View the Supporter Yearbook.
   
   Forum Home   Thread Marks Chat! Downloads Search Login Register  
Pages: [1]   Go Down
  Reply  |  New Topic  |  Print  
Author Topic: IDEA: Add/Update Increment to File Extension  (Read 3074 times)
AzureToad
Charter Member
***
Posts: 26


see users location on a map View Profile Read user's biography. Give some DonationCredits to this forum member
« on: October 27, 2009, 03:32:11 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!
Logged

____________________
while (!sleep)
   {
      sheep++
   }
MilesAhead
Member
**
Posts: 4,969



View Profile WWW Give some DonationCredits to this forum member
« Reply #1 on: October 27, 2009, 03:56:12 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:48 PM by MilesAhead » Logged

"Genius is not knowing you can't do it that way."
- MilesAhead
AzureToad
Charter Member
***
Posts: 26


see users location on a map View Profile Read user's biography. Give some DonationCredits to this forum member
« Reply #2 on: October 27, 2009, 05:36:54 PM »

VMS.
* AzureToad shudders.    Grin

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:

Quote
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.
Logged

____________________
while (!sleep)
   {
      sheep++
   }
MilesAhead
Member
**
Posts: 4,969



View Profile WWW Give some DonationCredits to this forum member
« Reply #3 on: October 27, 2009, 09:08:16 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.
Logged

"Genius is not knowing you can't do it that way."
- MilesAhead
awopbamboo
Honorary Member
**
Posts: 112



see users location on a map View Profile Give some DonationCredits to this forum member
« Reply #4 on: October 28, 2009, 09:13:03 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...

* FileReNum.exe (190 KB - downloaded 114 times.)
Logged

_____________________________________________
J.
AzureToad
Charter Member
***
Posts: 26


see users location on a map View Profile Read user's biography. Give some DonationCredits to this forum member
« Reply #5 on: October 28, 2009, 11:07:44 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?
Logged

____________________
while (!sleep)
   {
      sheep++
   }
awopbamboo
Honorary Member
**
Posts: 112



see users location on a map View Profile Give some DonationCredits to this forum member
« Reply #6 on: October 28, 2009, 11:15:52 AM »

Pascal, freepascal.

http://www.freepascal.org/

I usually use, Delphi or FreePascal/Lazarus

Logged

_____________________________________________
J.
MilesAhead
Member
**
Posts: 4,969



View Profile WWW Give some DonationCredits to this forum member
« Reply #7 on: October 31, 2009, 05:07: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:41 PM by MilesAhead » Logged

"Genius is not knowing you can't do it that way."
- MilesAhead
Pages: [1]   Go Up
  Reply  |  New Topic  |  Print  
 
Jump to:  
   Forum Home   Thread Marks Chat! Downloads Search Login Register  

DonationCoder.com | About Us
DonationCoder.com Forum | Powered by SMF
[ Page time: 0.034s | Server load: 0.04 ]