-2

I have a command prompt batch file with two menu options 1, that creates a txt file and adds text from a user input to it, and 2 that deletes said file.

I would like to expand option 1 if it's executed again that it adds text to the bottom of the file rather than overwriting it?

It works well but if the code is executed again it just writes over the file , I would like it to edit it and add the text to the bottom of the file.

Many Thanks

echo off
cls

set /p m= Enter 1 to add content to the text file, press 2 to delete the text file. 

:MENU 
if %m%==1 GOTO ADD
if %m%==2 GOTO DELETE 

:ADD
set /p input- Enter the text you want to add to the file:

echo %input% >Test.txt

GOTO PAUSE

:DELETE
del Test.txt
echo File Deleted.

GOTO PAUSE

:PAUSE
pause
aschipfl
  • 33,626
  • 12
  • 54
  • 99

2 Answers2

0

Use >> instead of >

echo %input% >> Test.txt
Trevor
  • 177
  • 5
-1
echo %input%>>yourfile.txt

Kindly avoid using space in between your input, the two >>s and the target file

mightyteja
  • 825
  • 1
  • 14
  • 38
oh no
  • 118
  • 6