Loading varibles from file

July 4, 2009 at 08:34:42
Specs: Windows Vista, 8g

I'm in the process of writing a batch program and I am wondering if I can load a variable from a file. EG, if the file is named "test" and the variable "aaa" is the only data in file "test" how can i load it so it will display when i type 'echo %b%'.

Thanks in advance for any help in this issue.

See More: Loading varibles from file

Report •

July 4, 2009 at 08:50:47
Explain better what you mean by

"the variable in the file is aaa and I want to display echo %b%"

What is the relation between aaa and %b%?

Report •

July 4, 2009 at 09:14:26
aaa being the first line in file 'test' and %b% being the variable in the batch file i wnt to set to aaa (the varible loaded from the file 'test'.

Report •

July 4, 2009 at 09:38:20
set /P b=<test
echo %b%

Report •

Related Solutions

July 4, 2009 at 19:16:13
Thank you very much, this works perfectly.

Report •

July 4, 2009 at 20:08:15
Hi, another question to add to this topic, what if i want to load the second line or the third line, is this possible?

Report •

July 5, 2009 at 03:15:41
Yes, it is possible, but that requires more advanced NT batch scripting. First of all start your batch by coding

@echo off & setlocal EnableDelayedExpansion

That enables the delayed expansion of variables that must be referenced by the ! symbol instead of the usual %. To know more type Set /? at the prompt and you get an on-line quick (unfriendly) tutorial.

Here how to read the third line

set myline=3
set line=0
for /F "delims=" %%j in (test.txt) do (
  set /A line+=1
  if !line! equ !myline! (set myvar=%%j& goto :DONE)
echo.Line #!myline! contains !myvar!

Report •

July 5, 2009 at 04:40:16
thanks, it worked great

Report •

Ask Question