使用命令提示符批处理文件将新行文本添加到txt文件中

问题描述 投票:0回答:1

我有一个带有两个菜单选项的命令提示符批处理文件,其中一个创建一个txt文件,并向用户输入文本,第二个删除该文件。

如果要再次执行选项1,即将文本添加到文件底部而不是覆盖它,我想扩展选项1?

[效果很好,但是如果再次执行代码,它只会覆盖文件,我希望对其进行编辑并将文本添加到文件底部。

非常感谢

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
file batch-file line dos
1个回答
0
投票

使用>>代替>

echo %input% >> Test.txt
© www.soinside.com 2019 - 2024. All rights reserved.