gpt4 book ai didi

batch-file - 批处理文件上的多项选择菜单?

转载 作者:行者123 更新时间:2023-12-04 01:08:01 24 4
gpt4 key购买 nike

嗨,我想制作一个批处理文件菜单,询问“选择要安装的应用程序?”。例如

  • App1
  • App2
  • App3
  • App4
  • App5
  • 所有应用程序

  • 选择哪个应用程序:_

    我想要的是,例如,我想安装App2,App3和App5,因此我可以通过App ID的“Select what app:2,3,5”进行输入。当用户选择选项6时,它将安装所有应用程序!

    我知道这在bash脚本上是可能的,但是我不确定在批处理脚本上吗?

    批处理菜单的一个示例是 http://mintywhite.com/software-reviews/productivity-software/create-multiple-choice-menu-batchfile/

    最佳答案

    回答

    这将做您想要的。如果您有任何疑问,请告诉我。您所要做的就是按照脚本中列出的两个步骤进行操作。

    脚本

    :: Hide Command and Set Scope
    @echo off
    setlocal EnableExtensions

    :: Customize Window
    title My Menu

    :: Menu Options
    :: Specify as many as you want, but they must be sequential from 1 with no gaps
    :: Step 1. List the Application Names
    set "App[1]=One"
    set "App[2]=Two"
    set "App[3]=Three"
    set "App[4]=Four"
    set "App[5]=Five"
    set "App[6]=All Apps"

    :: Display the Menu
    set "Message="
    :Menu
    cls
    echo.%Message%
    echo.
    echo. Menu Title
    echo.
    set "x=0"
    :MenuLoop
    set /a "x+=1"
    if defined App[%x%] (
    call echo %x%. %%App[%x%]%%
    goto MenuLoop
    )
    echo.

    :: Prompt User for Choice
    :Prompt
    set "Input="
    set /p "Input=Select what app:"

    :: Validate Input [Remove Special Characters]
    if not defined Input goto Prompt
    set "Input=%Input:"=%"
    set "Input=%Input:^=%"
    set "Input=%Input:<=%"
    set "Input=%Input:>=%"
    set "Input=%Input:&=%"
    set "Input=%Input:|=%"
    set "Input=%Input:(=%"
    set "Input=%Input:)=%"
    :: Equals are not allowed in variable names
    set "Input=%Input:^==%"
    call :Validate %Input%

    :: Process Input
    call :Process %Input%
    goto End


    :Validate
    set "Next=%2"
    if not defined App[%1] (
    set "Message=Invalid Input: %1"
    goto Menu
    )
    if defined Next shift & goto Validate
    goto :eof


    :Process
    set "Next=%2"
    call set "App=%%App[%1]%%"

    :: Run Installations
    :: Specify all of the installations for each app.
    :: Step 2. Match on the application names and perform the installation for each
    if "%App%" EQU "One" echo Run Install for App One here
    if "%App%" EQU "Two" echo Run Install for App Two here
    if "%App%" EQU "Three" echo Run Install for App Three here
    if "%App%" EQU "Four" echo Run Install for App Four here
    if "%App%" EQU "Five" echo Run Install for App Five here
    if "%App%" EQU "All Apps" (
    echo Run Install for All Apps here
    )

    :: Prevent the command from being processed twice if listed twice.
    set "App[%1]="
    if defined Next shift & goto Process
    goto :eof


    :End
    endlocal
    pause >nul

    关于batch-file - 批处理文件上的多项选择菜单?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14529246/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com