多字符批次选择菜单 [英] Multi-character batch choice menu

查看:136
本文介绍了多字符批次选择菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

快速的问题:
我已经在批处理文件中看到单字符选择菜单无处不在,但你如何让多个字符的选择菜单?

下面是一个例子(不工作):

 关闭@echo
回声示例菜单
GOTO AGAIN:再次
   CD / D%〜DP0
   回声恢复,应用程序,重新启动   集/ p =回答
   如果/我%回答:〜1%EQU1GOTO RESTORE
   如果/我%回答:〜1%EQU2GOTO APPS
   如果/我%回答:〜1%EQU0关机-t 0 -r -f   如果答案==恢复GOTO RESTORE
   如果答案==应用程序GOTO APPS
   如果答案==重启关机-t 0 -r -f:恢复
    启动systempropertiesprotection -k
    GOTO AGAIN:应用
    启动APPWIZ.CPL -k
    GOTO AGAIN


解决方案

您必须使用变量%答案%,不是字符串答案

 关闭@echo
回声示例菜单:再次
   CD / D%〜DP0
   回声恢复,应用程序,重新启动   集/ p =回答   如果/ I答案%%==恢复GOTO RESTORE
   如果/ I答案%%==应用程序GOTO APPS
   如果/ I答案%%==重启GOTO RESTART   回声这不是一个有效的选项。
   GOTO AGAIN:恢复
    回声你想恢复?
    GOTO AGAIN:应用
    呼应你想要的应用程序?
    GOTO AGAIN:重新开始
    回声你想重新开始吗?
    GOTO AGAIN

Quick question: I've seen single-character choice menus in batch files everywhere but how do you make multiple character choice menus?

Here's an example (doesn't work):

@echo off
echo Example Menu
GOTO AGAIN

:AGAIN
   CD /D "%~dp0"
   echo Restore, Apps, Restart

   set /p answer=
   if /i "%answer:~,1%" EQU "1" GOTO RESTORE
   if /i "%answer:~,1%" EQU "2" GOTO APPS
   if /i "%answer:~,1%" EQU "0" shutdown -t 0 -r -f

   if "answer"=="restore" GOTO RESTORE
   if "answer"=="apps" GOTO APPS
   if "answer"=="restart" shutdown -t 0 -r -f

:RESTORE
    start systempropertiesprotection -k
    GOTO AGAIN

:APPS
    start appwiz.cpl -k
    GOTO AGAIN

解决方案

You have to use the variable "%answer%", not the string "answer".

@echo off
echo Example Menu

:AGAIN
   CD /D "%~dp0"
   echo Restore, Apps, Restart

   set /p answer=

   if /i "%answer%" == "restore" GOTO RESTORE
   if /i "%answer%" == "apps" GOTO APPS
   if /i "%answer%" == "restart" GOTO RESTART

   echo That was not a valid option.
   GOTO AGAIN

:RESTORE
    echo You want to restore?
    GOTO AGAIN

:APPS
    echo You want apps?
    GOTO AGAIN

:RESTART
    echo You want to restart?
    GOTO AGAIN

这篇关于多字符批次选择菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆