BATCH programming help wanted
-
- New Member
- Posts: 12
- Joined: Thu Jun 03, 2004 5:46 pm
BATCH programming help wanted
I'm making a text adventure game using BATCH, and in order to make it work, I need to know how to get batch to add a line to an outside text document without bringing the document up, and I need to know to get it to take it away from that document, and finally I need to know how to make the program only perform an action if that line does or does not exist. I have windows xp. Thanks for any help
Start>Run
%systemroot%\hh.exe mk:@MSITStore: %systemroot%\help\ms-its:ntcmds.chm::/ntcmds.htm
The above command brings up the WinXP CommandLine-Reference (in case you didn't know)
1."I need to know how to get batch to add a line to an outside text document without bringing the document up"
Look into using the "type' command.
You can have it redirect the contents of a file to another file.
eg:
If you create a file named test.txt and put a line of text into it you can have that text added to another file using the redirector >> to "append" or add the text to a newfile.
type test.txt>>newfile.txt
(copies the text in 'test.txt' to 'newfile.txt')
For answers to the other questions look into the 'find' command. You can locate 'strings' in files etc.
From there depending on your knowledge of Dos, and/or the commandline, you can figure out the rest.
I would detail it for you, but it's something I have never done, never had a reason to.
Good luck.
%systemroot%\hh.exe mk:@MSITStore: %systemroot%\help\ms-its:ntcmds.chm::/ntcmds.htm
The above command brings up the WinXP CommandLine-Reference (in case you didn't know)
1."I need to know how to get batch to add a line to an outside text document without bringing the document up"
Look into using the "type' command.
You can have it redirect the contents of a file to another file.
eg:
If you create a file named test.txt and put a line of text into it you can have that text added to another file using the redirector >> to "append" or add the text to a newfile.
type test.txt>>newfile.txt
(copies the text in 'test.txt' to 'newfile.txt')
For answers to the other questions look into the 'find' command. You can locate 'strings' in files etc.
From there depending on your knowledge of Dos, and/or the commandline, you can figure out the rest.
I would detail it for you, but it's something I have never done, never had a reason to.
Good luck.
Hi,
As the first reply says you can:
type someline >> firstfile
But if you want to get it out, things get more comples. Maybe this:
copy firstfile firstfile.sav
type someline >> firstfile
then if you want the original back:
copy firstfile.sav firstfile
As to checking to see if the added line is in the file, you can use find:
find "the string I added" firstfile
if errorlevel 1 [it's not there so do whatever]
goto end
[it is there so do something else]
**
Hope this helps
As the first reply says you can:
type someline >> firstfile
But if you want to get it out, things get more comples. Maybe this:
copy firstfile firstfile.sav
type someline >> firstfile
then if you want the original back:
copy firstfile.sav firstfile
As to checking to see if the added line is in the file, you can use find:
find "the string I added" firstfile
if errorlevel 1 [it's not there so do whatever]
goto end
[it is there so do something else]
**
Hope this helps
-
- New Member
- Posts: 12
- Joined: Thu Jun 03, 2004 5:46 pm
:)





this is an update to my last question, for anyone who cares, (probably nobody). To save anything to a file, just use echo combined with redirector commands!!
@echo off
:start
echo Enter a string to be saved to "savedstring.txt".
set /p string=
echo You entered %string%.
echo Now going to save %string% to a file.
pause
echo %string%>>savedstring.txt
goto start
the above code will create the folder called savedstring.txt, and will add the string you entered to it, and then allows you to add another string, and so on
the following 2 programs, run separately, would create and load a loadable text
program 1:
@echo off
:start
echo Enter a string to be saved.
set /p var=
echo You entered %var%.
echo Now going to save %var% to file.
pause
echo set var=%var%>>savednumber.dat
after running that program, load this one:
@echo off
:start
echo This program will allow you to load the text you saved.
echo Have you loaded it already? (y/n)
set /p choice=
set choice=%choice:~0,1%
if '%choice%'=='y' goto yes
if '%choice%'=='n' goto no
echo "%choice%" is not a valid option.
goto start
:no
pause
type savednumber.dat>>loadstring.bat
echo call loadnumber.cmd>>loadstring.bat
pause
call loadstring.bat
:yes
pause
echo The string you saved was: %var%.
pause
*pats himself on back*