Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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 codeWHY?
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 accordinglyAs 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."

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

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.
::/CODEfor chat (changes color according to file)
::CODE/
set color=0F
if exist col.txt set /p color=<col.txt
color %color%
::/CODEThanks 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."

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

![]() |
![]() |
![]() |

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