Results 1 to 6 of 6

Thread: BATCH programming help wanted

  1. #1

    Question 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

  2. #2
    Elite Member Norm's Avatar
    Join Date
    Mar 2001
    %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.
    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.

  3. #3

    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

  4. #4


    Last edited by Sparky•The•Elf; 06-10-04 at 06:47 PM.

  5. #5

    Wink :)

    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
    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.
    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
    echo Enter a string to be saved.
    set /p var=
    echo You entered %var%.
    echo Now going to save %var% to file.
    echo set var=%var%>>savednumber.dat

    after running that program, load this one:

    @echo off
    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
    type savednumber.dat>>loadstring.bat
    echo call loadnumber.cmd>>loadstring.bat
    call loadstring.bat
    echo The string you saved was: %var%.

    *pats himself on back*

  6. #6
    Junior Member
    Join Date
    Apr 2010
    Thats awesome sparky!

    But no matter what site i look at i cannot find anything that tells you advanced commands like

    set choice=%choice:~0,1% ??? Where did you learn that? And what does it mean?

    I am pretty decent at batch now, but im just limited by the information i can find on the web.


Similar Threads

  1. Just wanted to say
    By IRS in forum General Discussion Board
    Replies: 5
    Last Post: 01-28-04, 07:16 PM
  2. Replies: 6
    Last Post: 11-26-02, 07:21 PM
  3. Batch File Bonanza,SiS 645 Pentium 4 DDR Chipset, More
    By minir in forum General Discussion Board
    Replies: 0
    Last Post: 12-09-01, 09:31 AM
  4. How do i get rid of these files, with a batch file?
    By newbie69 in forum Software Forum
    Replies: 7
    Last Post: 09-15-01, 04:02 PM
  5. Systems Analysis or Programming? Advice needed.
    By Humboldt in forum General Discussion Board
    Replies: 5
    Last Post: 01-23-01, 07:07 PM


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts