如何使用定义的菜单类型列表来运行一系列选择,即一次有条件地勾选所选项目。
传统上,配置器看起来像这样:
@echo off
chcp 1251 >nul
:begin
echo [1] Folder 1 [3] Folder 3
echo [2] Folder 2 [4] Folder 4
set /P op=Enter the number:
if "%op%"=="1" goto op1
if "%op%"=="2" goto op2
if "%op%"=="3" goto op3
if "%op%"=="4" goto op4
:op1
cls
call "Delete_Folder1.bat" >nul
echo Done
timeout /t 2 >nul
cls
goto begin
:op2
cls
call "Delete_Folder2.bat" >nul
echo Done
timeout /t 2 >nul
goto begin
:op3
cls
call "Delete_Folder3.bat" >nul
echo Done
timeout /t 2 >nul
cls
goto begin
:op4
cls
call "Delete_Folder4.bat" >nul
echo Done
timeout /t 2 >nul
cls
goto begin
我不明白如何一次选择多个项目。有条件1和3,或者2、3和4,即连续列出几项,并全部满足。
使用
for
循环处理列表非常简单:
@echo off
setlocal
set /P "op=Enter the number(s, separated by space or comma): "
echo DEBUG: %op%
for %%i in (%op%) do call :op%%i 2>nul|| goto :fail
goto :eof
:op1
echo one
goto :eof
:op2
echo two
goto :eof
:op3
echo three
goto :eof
:op4
echo four
goto :eof
:fail
echo wrong input
goto :of
可能需要更多验证输入是否正确。