Computing.Net > Forums > Disk Operating System > Set variable equal to file data

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.

Set variable equal to file data

Reply to Message Icon

Name: Guy Smiley
Date: October 11, 2002 at 11:13:42 Pacific
OS: Win2K Command Prompt
CPU/Ram: 750 Mhz / 256 MB
Comment:

How can I set a variable to be equal to the data in a file on Win2K DOS? Thanks.



Sponsored Link
Ads by Google

Response Number 1
Name: bitbyte
Date: October 11, 2002 at 12:06:03 Pacific
Reply:

which content has such a file?


0

Response Number 2
Name: Secret_Doom
Date: October 11, 2002 at 18:53:12 Pacific
Reply:

A good option would be to use the FOR cmd with the /F switch. But how to use it depends on how should the text be handled.

Let's say you want to send each line from filename.ext to a variable, one line by one:

for /F "tokens=*" %%A in (filename.ext) do (
echo Line processed:
echo %%A
)

You might want to send the first line from the file entirely to a certain variable (enviromental variable, like %var%, not like %%A), and just the first line:

for /F "tokens=*" %%A in (filename.ext) do (
set LINE=%%A
goto forend
)
:forend
echo LINE=%LINE%

You didn't say how the text should be handled, so I can't post a specific solution.

Tell us how is that file (give an example of the file and of what should be passed to the variable) and we can tell you a solution. You could also try to learn the sintax. By typing "FOR/?" on the command prompt, you'll get a very good information about the command (good enough to learn it).

BTW, there's no "Win2K DOS". There's a command interpreter, CMD.EXE, which looks like DOS's command interpreter, COMMAND.COM. Nevertheless, that's not DOS, not at all.

-- Leonardo Pignataro - Secret_Doom --

secret_doom@hotmail.com
www.batch.hpg.com.br


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


proxy Lte 286



Post Locked

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


Go to Disk Operating System Forum Home


Sponsored links

Ads by Google


Results for: Set variable equal to file data

dos printing to file www.computing.net/answers/dos/dos-printing-to-file/11516.html

setting a dos variable from text file www.computing.net/answers/dos/setting-a-dos-variable-from-text-file/7785.html

Batch Files: set variable to output www.computing.net/answers/dos/batch-files-set-variable-to-output/16926.html