【问题标题】:All option in choice command选择命令中的所有选项
【发布时间】:2018-07-23 19:45:06
【问题描述】:

我想知道在批量构建选项菜单时是否有一种简洁明了的方式来添加“选择所有选项”。

目前我的选项设置为清除项目 1、清除项目 2、清除项目 3(全部清除)、退出和用户看不到的超时。

如果需要,我会将所有代码重新添加到“全部清除”区域。我希望看看是否有办法让“全部清除”使用定义的 1 和 2,然后像其他所有内容一样返回 :start。

答案:我采纳了 Aacini 关于“设置选项”的想法,并想出了一个更简单的答案。我将“清除所有选项”更改为“GOTO :start"to"GOTO :ClearCache”。然后我添加了一个“IF %ERRORLEVEL% neq 3 GOTO :start”,然后添加了一个“GOTO :ClearCredentials”。这让我保留的行数比设置选项少,而且我不必移动我的代码就可以让它传递到下一个进程。

这应该允许多个但不同的清除未来项目的所有选项。

@ECHO OFF
:start
ECHO 1. Clear IE, Chrome, Temp Cache
ECHO 2. Clear Credentials in IE, Chrome, and Windows
ECHO 3. Clear All Options
ECHO 4. Exit
CHOICE /N /C:12345 /T 15 /D 5 /M "Type the number to choose an option."
IF %ERRORLEVEL%==5 GOTO TIMEOUT
IF %ERRORLEVEL%==4 GOTO Exit
IF %ERRORLEVEL%==3 GOTO ClearAllOptions
IF %ERRORLEVEL%==2 GOTO ClearCredentials
IF %ERRORLEVEL%==1 GOTO ClearCache
GOTO :start

:ClearCache
ECHO Clearing Cache...
<code here>
pause
cls
IF %ERRORLEVEL% neq 3 GOTO :start
GOTO :ClearCredentials


REM ===-----------------------

:ClearCredentials
ECHO Clearing Credentials
<code here>
pause
cls
GOTO :start

REM ===-----------------------

:ClearAllOptions
ECHO Clearing All Options...
pause
cls
GOTO :ClearCache
pause

REM ===-----------------------

:Exit
ECHO Exiting...
<code here>
pause
EXIT

REM ===-----------------------

:TIMEOUT
cls
ECHO Exiting because no choices were made in 15 seconds
:END
timeout /t 5

【问题讨论】:

    标签: batch-file cmd menu choice


    【解决方案1】:

    这是一个非常简单的方法:

    @ECHO OFF
    :start
    set option=0
    
    ECHO 1. Clear IE, Chrome, Temp Cache
    ECHO 2. Clear Credentials in IE, Chrome, and Windows
    ECHO 3. Clear All Options
    ECHO 4. Exit
    CHOICE /N /C:12345 /T 15 /D 5 /M "Type the number to choose an option."
    GOTO Option-%ERRORLEVEL%
    
    :Option-3 ClearAllOptions
    ECHO Clearing All Options
    set option=3
    
    :Option-1 ClearCache
    ECHO Clearing Cache...
    <code here>
    pause
    cls
    if %option% neq 3 GOTO :start
    
    REM ===-----------------------
    
    :Option-2 ClearCredentials
    ECHO Clearing Credentials
    <code here>
    pause
    cls
    GOTO :start
    
    REM ===-----------------------
    
    :Option-4 Exit
    ECHO Exiting...
    <code here>
    pause
    EXIT
    
    REM ===-----------------------
    
    :Option-5 TIMEOUT
    cls
    ECHO Exiting because no choices were made in 15 seconds
    :END
    timeout /t 5
    

    【讨论】:

      猜你喜欢
      • 2017-12-31
      • 2011-06-21
      • 2011-04-08
      • 1970-01-01
      • 1970-01-01
      • 2013-06-13
      • 2023-03-23
      • 2012-01-16
      • 1970-01-01
      相关资源
      最近更新 更多