Multiple choices menu on batch file?

后端 未结 13 1681
盖世英雄少女心
盖世英雄少女心 2020-11-28 12:56

Hi I want to make a batch file menu, that asks \'Select app you want to install?\' for example

  1. App1
  2. App2
  3. App3
  4. App4
  5. App5
13条回答
  •  日久生厌
    2020-11-28 13:42

    I saw that none of the above answers completely answered his/her question. One feature that they have left out is selecting all the software it installs in one go (so to speak).

    So I made this off the top of my head (extremely sorry if there is something wrong with it, I'll edit it if there is).

    @echo off & setlocal enabledelayedexpansion
    
    echo What would you like to install?
    ::Put your options here, preferably numbered.
    set /p op=Type the numbers of the software you want to install (separated by commas with no spaces. E.g: 1,3,2): 
    
    for /f "delims=, tokens=1-5" %%i in ("op") do (
    set i=%%i
    set j=%%j
    set k=%%k
    set l=%%l
    set m=%%m
    )
    if %i%X neq X set last=1b & goto %i%
    :1b
    if %j%X neq X set last=2b & goto %j%
    :2b
    if %k%X neq X set last=3b & goto %k%
    :3b
    if %l%X neq X set last=4b & goto %l%
    :4b
    if %m%X neq X set last=%m% & goto %m%
    goto next
    
    :1
    ::Put the code for doing the first option here
    goto %last%
    :2
    ::Put the code for doing the second option here
    goto %last%
    :3
    ::Put the code for doing the third option here
    goto %last%
    :4
    ::Put the code for doing the fourth option here
    goto %last%
    :5
    ::Put the code for doing the fifth option here
    goto %last%
    

    :next ::Put some more stuff here...

    So that was a bit excessive. Feel free to change some things around and such.

    What the code is doing is getting the user input (such as if you put in "1,3,4"), putting each number into its own variable, checking if that variable is empty, and if it isn't, sending you to code that does whatever the option was. It does this a few times until all the variables have been assessed.

提交回复
热议问题