如何批量编辑txt文件?

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

所以现在,我正在尝试弄清楚如何使批处理程序的用户可以编辑 .txt 文件。我已经有了创建该文件的批处理文件,但现在我需要制作它,以便 .txt 文件包含用户对问题的回答。这是我现在拥有的:

@echo off
echo Welcome to the Space Mapping Discord Report Maker
pause
echo Made by N3ther, version 0.1 ALPHA
pause
@echo off
break>"%userdomain%\%username%\Desktop\report.txt"
echo Question 1: What is your username on Discord?`

(这是给我担任主持人的报告制作者的。)

batch-file text
1个回答
0
投票

看起来像下面这样的东西就是你所需要的:

@echo off
setlocal EnableExtensions EnableDelayedExpansion
set "ReportFile=%USERPROFILE%\Desktop\report.txt"
del "%ReportFile%" 2>nul

echo Welcome to the Space Mapping Discord Report Maker
echo(
echo Made by N3ther, version 0.1 ALPHA
echo(

call :PromptUser 1 "What is your username on Discord?"
call :PromptUser 2 "What is ...?"

rem Restore saved environment and exit batch processing.
endlocal
exit /B

rem This small subroutine prompts the user for an input until something is
rem entered at all and then appends the entered input to the report file.

:PromptUser
set "Input="
:PromptAgain
set /P "Input=Question %~1: %~2 "
rem Has the user entered anything at all?
if not defined Input goto PromptAgain
echo !Input!>>"%ReportFile%"
goto :EOF

要了解所使用的命令及其工作原理,请打开命令提示符窗口,执行以下命令,并完整、仔细地阅读每个命令显示的帮助页面。

  • call /?
  • del /?
  • echo /?
  • endlocal /?
  • exit /?
  • goto /?
  • if /?
  • rem /?
  • set /?
  • setlocal /?

另请阅读有关 使用命令重定向运算符的 Microsoft 文档以及有关 Windows 环境变量的 Wikipedia 文章。

© www.soinside.com 2019 - 2024. All rights reserved.