Computing.Net > Forums > Programming > Batch = Store 1 number at a time

Batch = Store 1 number at a time

Reply to Message Icon

Original Message
Name: cool_andy
Date: May 1, 2007 at 09:23:12 Pacific
Subject: Batch = Store 1 number at a time
OS: Windows XP
CPU/Ram: 512
Model/Manufacturer: Acer
Comment:

Hi I have created a batch file that will restore the original version numbers to all necessary files in Visual Source Safe.
The unix commands work from executable files.

@echo off

rem get directories
cat exth.txt | grep "History of" > temp.txt

rem replace "History of" text with blank space
sed s/"History of"//g temp.txt > temp2.txt

rem remove 3 full stops at the end of each line
sed 's/...$//' temp2.txt > tempdirectories.txt

rem get and store history of version in new textfile
cat exth.txt | grep "Version " > tempversions.txt

rem run next batch file to store version numbers in variables
set No=0
for /f "tokens=2" %%a in (tempversions.txt) do (
set /a No+=1

call getversion.bat %%a

)

set No=0
for /f %%a in (tempdirectories.txt) do (
set /a No+=1

set current = %version%No%% - does not work!
echo %current%
rem uncomment to test - pin all files to assigned version number
rem ss pin "%%a" "-V%current%"
)


The problem I am having is reading each version number in turn from a variable so I can pin each file in sourcesafe. This command does not seem to store the variable:
set current = %version%No%%

The getversion.bat contains the following and works successfully:
set version%No%=%1

Thank you for your help
Regards
Andrew Ashcroft


Report Offensive Message For Removal

Response Number 1
Name: cool_andy
Date: May 2, 2007 at 07:39:35 Pacific
Subject: Batch = Store 1 number at a time
Reply: (edit)

Would it be possible to store the version numbers in an array rather than varaibles because have at least 200-300 version numbers retrieved from a textfile.



Report Offensive Follow Up For Removal

Response Number 2
Name: cool_andy
Date: May 2, 2007 at 11:20:03 Pacific
Subject: Batch = Store 1 number at a time
Reply: (edit)

Ok I figured how to store the numbers in an array, by calling another bat file in a loop:

set No=0
for /f "tokens=2" %%a in (tempversions.txt) do (
set /a No+=1
call current.bat %%a

)

current.bat contains:
set version.%No%=%1

Now I have the problem of displaying and using each version number in turn.

This command does not work
echo %version.%No%%

Say if the varaible No was 267.
Set No=267
When I type that exact echo command above in "cmd" prompt window, I get:
%version.267%

It should be 18.

Can anyone help me please?

Thank you

Andrew


Report Offensive Follow Up For Removal

Response Number 3
Name: tonysathre
Date: May 2, 2007 at 20:28:48 Pacific
Subject: Batch = Store 1 number at a time
Reply: (edit)

Instead of using external scripts, you can use labels by starting a line with a colon :

Such as the following;

:myLabel
your code from external script

And then using the CALL or GOTO command to 'call' that function.

So your code could be changed to the following, without the need for an external script;

set No=0
for /f "tokens=2" %%a in (tempversions.txt) do (
set /a No+=1
goto current %%a

:current
set version.%No%=%1


Also, this command is the correct way to display that var:

echo %version.%No%%

should be

echo %version.%%NO%

Each var needs to be surrounded with % signs.

I also would recommand using blocks for comments instead of the rem command because it is easy to read and see in the code.

::This is a comment

"Computer security." — Oxymoron


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Batch = Store 1 number at a time 

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software