Computing.Net > Forums > Programming > Loading varibles from file

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Loading varibles from file

Reply to Message Icon

Name: bignold
Date: July 4, 2009 at 08:34:42 Pacific
OS: Windows Vista
CPU/Ram: 8g
Product: Custom / CUSTOM BUILT
Subcategory: Batch
Comment:

Hi,

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.



Sponsored Link
Ads by Google

Response Number 1
Name: IVO
Date: July 4, 2009 at 08:50:47 Pacific
Reply:

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%?


0

Response Number 2
Name: bignold
Date: July 4, 2009 at 09:14:26 Pacific
Reply:

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'.


0

Response Number 3
Name: IVO
Date: July 4, 2009 at 09:38:20 Pacific
Reply:

set /P b=<test
echo %b%


0

Response Number 4
Name: bignold
Date: July 4, 2009 at 19:16:13 Pacific
Reply:

Thank you very much, this works perfectly.


0

Response Number 5
Name: bignold
Date: July 4, 2009 at 20:08:15 Pacific
Reply:

Hi, another question to add to this topic, what if i want to load the second line or the third line, is this possible?


0

Related Posts

See More



Response Number 6
Name: IVO
Date: July 5, 2009 at 03:15:41 Pacific
Reply:

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)
)
:DONE
echo.Line #!myline! contains !myvar!


0

Response Number 7
Name: bignold
Date: July 5, 2009 at 04:40:16 Pacific
Reply:

thanks, it worked great


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Loading varibles from file

Load a batch file as a TSR www.computing.net/answers/programming/load-a-batch-file-as-a-tsr/8704.html

Load External XML file client side? www.computing.net/answers/programming/load-external-xml-file-client-side/11094.html

C++ random names from file www.computing.net/answers/programming/c-random-names-from-file/4753.html