Computing.Net > Forums > Programming > Assign file contents to batch var!

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.

Assign file contents to batch var!

Reply to Message Icon

Name: DeltaSlaya
Date: March 25, 2007 at 23:08:54 Pacific
OS: Windows XP Professional S
CPU/Ram: Intel Celeron 2.8ghz / 1g
Product: Custom
Comment:

I need to be able to assign the contents of a *.txt or *.log file to a variable in a batch instance.

1. open batch file
2. creates x.txt file with information X
3. batch file terminates
4. batch file is reopened
5. batch file assigns information X found
in file X to variable X
6. variable X is used in code

WHY?
I have a chat program I have made for use at school over the student (s:\) drive. There is also a 'master' version with features that can affect the other chat programs. I want to implement a color changing feature. I have it working currently although it is impracticable as there is a long delay while it checks for all existing files. The current script sort of works like this:

1. Master chat creates XX.col file
2. chat file checks for .col files:
CODE:
if exist 0B.col color 0B
if exist 0C.col color 0C
if exist 0D.col color 0D ... etc.
/CODE
3. color of batch instance is changed accordingly

As you can see very long winded and time consuming. Creating a file with the color variable in it would be a lot easier.

Thanks in advance, I would appreciate all possible help! =P

Contact me: deltaslaya@hotmail.com

ThanX o.O


-DeltaSlaya™
"This post is provided 'as-is', implies no warranties and confers no rights."



Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: March 26, 2007 at 01:35:40 Pacific
Reply:

Not sure I'm with you. Like this?

::==
@echo off
echo 0D>x.txt
set /p X=<x.txt
echo X=%X%
::==



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

M2



0

Response Number 2
Name: DeltaSlaya
Date: March 26, 2007 at 03:17:05 Pacific
Reply:

Thanks a lot dude, that works great.

To answer what I was trying to do:
I have made a chat program at my school that writes input to a file and then outputs it on screen (obviously). Though i have implemented other features for the purpose of increasing my programming skill. Such as banning and this 'color' thing. I had got it working but the code I used took too long to run through because I don't really know much about batch except what it tells you in /? etc. Thanks a lot though.

Any chance you have MSN?

I get all the code except this bit if you dont care to explain:
set /p X=<x.txt
I get the set, X and x.txt but not the < and /p (prompt), what function do they perform, why do u need the /p there?

Code I have now is something like this:

ON 'master chat' (creator of color file)
::CODE/
set col=
color /?
echo.
echo Color code:
(set /p col=? )
attrib -r col.txt
echo %col%>col.txt
attrib +r col.txt
echo.
echo Done.
::/CODE

for chat (changes color according to file)
::CODE/
set color=0F
if exist col.txt set /p color=<col.txt
color %color%
::/CODE

Thanks for help and if you could answer questions it would be appreciated!

-DeltaSlaya™
"This post is provided 'as-is', implies no warranties and confers no rights."


0

Response Number 3
Name: Mechanix2Go
Date: March 26, 2007 at 08:42:57 Pacific
Reply:

The set /p says to wait for input and this:

set /p X=<col.txt

sends the contents of col.txt as input to set /p.


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

M2



0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


Permissions to Registry k... Compare files with AWK



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: Assign file contents to batch var!

BATCH text file content to variable www.computing.net/answers/programming/batch-text-file-content-to-variable/16264.html

read file content using batch loop www.computing.net/answers/programming/read-file-content-using-batch-loop/17010.html

batch file help www.computing.net/answers/programming/batch-file-help/14148.html