批量是/否选项

Kor*_*kel 5 batch-file

我正忙着为自己构建一个脚本来清空不同的文件夹,但我想为用户做出是/否选择,其中 N 返回菜单,Y 运行脚本。

这就是我得到的:

:temp

CHOICE /C YN /M "Enter your choice:" 
IF ERRORLEVEL Y GOTO deltemp
IF ERRORLEVEL N goto reset

:reset
goto menu

:deltemp
Run Code Online (Sandbox Code Playgroud)

现在它直接进入菜单,我认为是由于 :reset 上面的内容 :deltemp 造成的。

npo*_*aka 4

errorlevel 只能有数值。CHOICE 命令设置为每个下一个字母递增 errorlevel:

:temp

CHOICE /C YN /M "Enter your choice:" 
IF ERRORLEVEL 2 goto reset
IF ERRORLEVEL 1 GOTO deltemp


:reset
goto menu

:deltemp
Run Code Online (Sandbox Code Playgroud)

  • @npocmaka 还没喝咖啡;)。我纠正了他的答案。请再试一次 (3认同)