|
Answer» Hi all,
I would like to create a batch program to automate file revisioning process. Everytime the batch program is executed, it will have to create a folder which will hold some files. The folder created should be named on the fly eg. ver-1.01, ver-1.02, ver-1.03, etc. That is, it should be able to create the folder by naming it with filename in a specific pattern+incremental numbering as the postfix.
Other than that, once it reaches ver-1.10, the batch program should know that the next folder to create should be named ver-2.01 and the list goes on till folder ver-2.10 is created and then it should create folder ver-3.01 instead of ver-2.11.
Anyone who has done this before or has any idea on how to do it, please help!
Thanks in advance! Code: [Select]SETLOCAL ENABLEDELAYEDEXPANSION set /p ver=<ver.txt for /f "tokens=1-2 delims=." %%A in ("%ver%") do ( set A=%%A set B=%%B ) if !B!==08 goto 9 if !B!==09 goto 10 if !B!==10 goto new set /a B=!B!+1 echo !A!.0!B!>ver.txt md !A!.0!B! exit
:new set /a A=!A!+1 set B="01" echo !A!.!B!>ver.txt MD !A!.!B! exit
:9 rem my computer doesn't think '9' or '10' is a number... :S set /a b=9 echo !A!.0!B!>ver.txt md !A!.0!B! exit
:10 rem my computer doesn't think '9' or '10' is a number... :S set /a b=10 echo !A!.!B!>ver.txt md !A!.!B! exit You'll have to create a text file called "ver.txt" with the first version you want to implement. I'm not SURE why it doesn't think that 8+1=9 but i had to make a workaround instead. Let us know if it works.
FBHi
This MAY answer Fireball's query about the problem with numbers 8 and 9.
numbers 0 to 9 are valid "base 10" numbers.
numbers 0x are often considered octal, in which case numbers 00 to 07 are valid octal numbers,above this the sequence continues 10 to 17. numbers 08 and 09 have no meaning in octal arithmetic.
My response is triggered by the 7th line of the batch script, i.e. if !B!==08 goto 9
Regards Alan An alternative to misinterpreting numbers as octal and eliminating delayed expansion, would be to combine the left and right DECIMAL as a whole number:
Code: [Select]@echo off set folder=c:\temp for /f "tokens=2-3 delims=.-" %%v in ('dir /b /o:-n /a:d %folder%\ver-* 2^>nul') do ( if errorlevel 1 goto first set digit=%%v set dec=%%w goto next ) :first md %folder%\ver-1.01 goto :eof
:next set /a worknum=%digit%%dec%+1 set dec=%worknum:~-2% if %dec% GTR 10 ( set /a digit=%digit%+1 set dec=01 )
md %folder%\ver-%digit%.%dec%
Be sure to change the folder name in line 2.
Yes, both ways work exactly to what I wanted to do. Thank you guys! Hi ALL,
Based on the SCRIPTS posted by Fireballs and Sidewinder below, what if I want to make the major number of the baseline to increase only by weekly and the minor number will be increased daily and if the script is ran more than once in a same day, the next folder to be created will be the 1st folder created on that day || '-' || x, where x is a running number?
In other words, every week the major number will increase, while daily the minor number will increase if there is any, if there are more than 2 baseline call in a day it will be followed by ‘-‘.
e.g 1/9 Monday baseline is 1.0 2/9 Tuesday baseline is 1.1 4/9 Thursday baseline is 1.2 4/9 Thursday second baseline is 1.2-1 4/9 Thursday third baseline is 1.2-2 8/9 Monday baseline is 2.0
Any help in this will be greatly appreciated. Thanks in advance!i can help but could you start a new topic please?
FBFB is right, start a new topic, and when you do please type echo %DATE% at a command prompt and post the results.
|