Batch file - Textfile input

April 23, 2007 at 12:38:28
Specs: XP - Command Prompt Cmd, 512

How can I input data from a textfile into an environment variable?
I tried this but it does not work correctly:
SET version < test.txt

The textfile contains
356
19
23
44
55
23
12

I would like to read in each Version number to store in a separate variable, which then can be used in Visual Source safe.

set version1 = 356
set version2 = 29
set version 3 = 73
set version 4 = 15
etc.

Followed by Source safe command:
- ss pin <directory> -V%version1%

Thank you for your help

Regards
Andrew Ashcroft


See More: Batch file - Textfile input

Report •


#1
April 23, 2007 at 13:44:01

Hi
I don't know anything about Source Safe
but this help

@echo off
setlocal EnableDelayedExpansion
set No=0
for /f %%a in (x.txt) do (
set /a No+=1
set Version!No!=%%a
)
set name


Report •

#2
April 24, 2007 at 03:51:34

Thank you.
It now seems to store the data from the text file but I only end up with 1 variable storing the last value.
version!No! = 356

Im not really familiar with Batch files but is it not possible to do IF statements to specify which variable to set?
For example within the For Loop:
IF No=1
set version 1 = %%a

IF No=2
set version 2 = %%a

Either that or there is alteranative syntax for Version!No! = %%aa

Thanks again



Report •

#3
April 24, 2007 at 13:03:32

Hi
Put echo in front of the 2nd set command.
I get the listing below, what do you get.

@echo off
setlocal EnableDelayedExpansion
set No=0
for /f %%a in (x.txt) do (
set /a No+=1
echo set Version!No!=%%a
)

---
Output of above command
x.txt contains no's 1-10
using the command "SET"

set Version1=1
set Version2=2
set Version3=3
set Version4=4
set Version5=5
set Version6=6
set Version7=7
set Version8=8
set Version9=9
set Version10=10


Report •

Related Solutions

#4
April 24, 2007 at 13:13:40

Hi dtech10


=====================================
If at first you don't succeed, you're about average.

M2



Report •

#5
April 24, 2007 at 14:31:33

Hi Mechanic

I wrote a batch program to calculate the old file date problem, which is a simpler than my previos version.
I just need to test it, I'll post it here shortly, it's only for WinXp ect.

I might try and write one for MsDos but thats a different kettle of fish.



Report •

#6
April 25, 2007 at 00:16:52

"I might try and write one for MsDos but thats a different kettle of fish."

Let the congregation say amen.



=====================================
If at first you don't succeed, you're about average.

M2



Report •


Ask Question