filebatch-filetext

How can I use a batch file to write to a text file?


I need to make a script that can write one line of text to a text file in the same directory as the batch file.


Solution

  • You can use echo, and redirect the output to a text file (see notes below):

    rem Saved in D:\Temp\WriteText.bat
    @echo off
    echo This is a test> test.txt
    echo 123>> test.txt
    echo 245.67>> test.txt
    

    Output:

    D:\Temp>WriteText
    
    D:\Temp>type test.txt
    This is a test
    123
    245.67
    
    D:\Temp>
    

    Notes: