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.
This question is related to
file
batch-file
text
@echo off
echo Type your text here.
:top
set /p boompanes=
pause
echo %boompanes%> practice.txt
hope this helps. you should change the string names(IDK what its called) and the file name
copy con
to write a long textExample:
C:\COPY CON [drive:][path][File name]
.... Content
F6
1 file(s) is copied
@echo off
(echo this is in the first line) > xy.txt
(echo this is in the second line) >> xy.txt
exit
The two >>
means that the second line will be appended to the file (i.e. second line will start after the last line of xy.txt).
this is how the xy.txt
looks like:
this is in the first line
this is in the second line
It's easier to use only one code block, then you only need one redirection.
(
echo Line1
echo Line2
...
echo Last Line
) > filename.txt
echo "blahblah"> txt.txt
will erase the txt and put blahblah in it's place
echo "blahblah">> txt.txt
will write blahblah on a new line in the txt
I think that both will create a new txt if none exists (I know that the first one does)
Where "txt.txt
" is written above, a file path can be inserted if wanted. e.g. C:\Users\<username>\desktop
, which will put it on their desktop.
@echo off Title Writing using Batch Files color 0a
echo Example Text > Filename.txt echo Additional Text >> Filename.txt
@ECHO OFF
Title Writing Using Batch Files
color 0a
echo Example Text > Filename.txt
echo Additional Text >> Filename.txt
Source: Stackoverflow.com