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
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%'.
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
Summary: Hi, I have been developing a program which will delete a list of registry keys. I use this as a removal tool because the uninstall program on my companies computers doesn't work. I have already writte...
Summary: I have to display a Yahoo! news feed on a webpage. This URL tells how to do it: http://www.elise.com/mt/archives/000242displaying_an_rss_newsfeed_on_your_site.php. The logic is simple, and it works gr...
Summary: Hi, I would like to assign random names for object from file. Does it make difference if it's txt or dat file? What class should i include and what member function open and read the file. Thank you. ...