我的代码需要一些帮助。
当脚本检测到保存文件时,它需要询问是否重新创建它。此时,我点击Y
表示是
,但它退出
。
代码如下:
:existing
echo Welcome to Androids: Became Human!
echo ==================================
echo.
echo It appears that you already created
echo configuration file. Would you like
echo to re-create it?
echo.
echo Please enter (Y,N):
set /p choice=
if %choice% == "y" goto welcome
if %choice% == "n" exit
if %choice% == "Y" goto recreation
if %choice% == "N" exit
最佳答案
两边都使用引号,下面是一个示例:
不好:
:existing
echo Welcome to Androids: Became Human!
echo ==================================
echo.
echo It appears that you already created
echo configuration file. Would you like
echo to re-create it?
echo.
echo Please enter (Y,N):
set /p choice=
if %choice% == "y" goto welcome
if %choice% == "n" exit
if %choice% == "Y" goto recreation
if %choice% == "N" exit
好:
:existing
echo Welcome to Androids: Became Human!
echo ==================================
echo.
echo It appears that you already created
echo configuration file. Would you like
echo to re-create it?
echo.
echo Please enter (Y,N):
set /p choice=
if "%choice%" == "y" goto welcome
if "%choice%" == "n" exit
if "%choice%" == "Y" goto recreation
if "%choice%" == "N" exit
此外,我还为您的代码制作了更好的版本:
:existing
echo Welcome to Androids: Became Human!
echo ==================================
echo.
choice /c ynY /cs /m "It appears that you already created the configuration file, would you like to save it"
cls
if "%errorlevel%" == "1" goto welcome
if "%errorlevel%" == "2" exit
if "%errorlevel%" == "3" goto recreation
关于batch-file - 用户输入后意外退出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54833497/