2017-10-12 52 views
-2

所以現在,我想弄清楚如何讓批處理程序的用戶編輯.txt文件。我已經有創建該文件的批處理文件,但是現在我需要創建該文件,以便.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?` 

(這是一個爲報告壺我主持的。)

回答

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 
goto :EOF 

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 /?
  • goto /?
  • if /?
  • rem /?
  • set /?
  • setlocal /?

閱讀也是微軟的文章關於Using Command Redirection Operators和維基百科文章關於Windows Environment Variables