选择菜单未选择正确的错误级别

Choice Menu not selecting correct errorlevels

我在执行正确错误级别的选择菜单时遇到问题。我的批处理文件转到第一项 (A),并执行它,无论我在菜单中通过键盘 select 选择哪个。在下面的示例中,如果我 select 'C',那么 (IF "%ERRORLEVEL%" =="c" GOTO :c495) 应该执行。我的问题是 (IF "%ERRORLEVEL%" =="a" GOTO :a299) 无论我按什么键都在执行。有人可以告诉我我的批处理文件有什么问题吗?

@echo off
    cls
        echo.
        echo          A   .99                 H   .99
        echo          B   .99                 I   .99
        echo          C   .95                 J  .95
        echo          D   .99                 K  .95
        echo          E   .99                 L  .95
        echo          F   .99                 M  .95
        echo          G   .95                 N  .95
        echo          ___________________________________
        echo.
        echo                   Press 'Q' to Quit


        echo.
        CHOICE /N /C:abcdefghijklmnq /M "  SELECT A LETTER "%1
    IF "%ERRORLEVEL%" =="q" GOTO :xEOF
    IF "%ERRORLEVEL%" =="n" GOTO :n4995
    IF "%ERRORLEVEL%" =="m" GOTO :m3995
    IF "%ERRORLEVEL%" =="l" GOTO :l2995
    IF "%ERRORLEVEL%" =="k" GOTO :k1995
    IF "%ERRORLEVEL%" =="j" GOTO :j1495
    IF "%ERRORLEVEL%" =="i" GOTO :i999
    IF "%ERRORLEVEL%" =="h" GOTO :h499
    IF "%ERRORLEVEL%" =="g" GOTO :g995
    IF "%ERRORLEVEL%" =="f" GOTO :f899
    IF "%ERRORLEVEL%" =="e" GOTO :e699
    IF "%ERRORLEVEL%" =="d" GOTO :d599
    IF "%ERRORLEVEL%" =="c" GOTO :c495
    IF "%ERRORLEVEL%" =="b" GOTO :b399
    IF "%ERRORLEVEL%" =="a" GOTO :a299



 :a299
IF NOT EXIST "*Cover (300 DPI).jpg" GOTO :NullFile
IF EXIST "*Cover (300 DPI).jpg" COPY "c:\Users\admin\Documents\ProgramData\Bin\PricesD Cover - 299.png" "blank12.png"
GOTO :Compile


 :b399
IF NOT EXIST "*Cover (300 DPI).jpg" GOTO :NullFile
IF EXIST "*Cover (300 DPI).jpg" COPY "c:\Users\admin\Documents\ProgramData\Bin\PricesD Cover - 399.png" "blank12.png"
GOTO :Compile

 :c495
IF NOT EXIST "*Cover (300 DPI).jpg" GOTO :NullFile
IF EXIST "*Cover (300 DPI).jpg" COPY "c:\Users\admin\Documents\ProgramData\Bin\PricesD Cover - 495.png" "blank12.png"
GOTO :Compile

 :d599
IF NOT EXIST "*Cover (300 DPI).jpg" GOTO :NullFile
IF EXIST "*Cover (300 DPI).jpg" COPY "c:\Users\admin\Documents\ProgramData\Bin\PricesD Cover - 599.png" "blank12.png"
GOTO :Compile

代码从这里继续,但从现在开始工作正常。 谢谢。

终于找到答案了。它需要一种完全不同的思考方式:

@echo off
    cls
        echo.
        echo          1   .99                 A   .99
        echo          2   .99                 B   .99
        echo          3   .95                 C  .95
        echo          4   .99                 D  .95
        echo          5   .99                 E  .95
        echo          6   .99                 F  .95
        echo          7   .95                 G  .95
        echo          ___________________________________
        echo.
        echo                   Press 'Q' to Quit




@echo off
setlocal enabledelayedexpansion

set "list=299,399,495,599,699,899,995,499,999,1495,1995,2995,3995,4995,q" 
set "allchoices=1234567abcdefghijklmnopqABCDEFGHIJKLMNOPQ"
set count=0
for %%A in (%list%) do (
  rem call echo %%allchoices:~!count!,1%%: %%A
  set /a count+=1
  set "list[!count!]=%%A"
)
set "choices=!allchoices:~0,%count%!"
choice /cs /N /C:1234567abcdefgqABCDEFGQ /M "SELECT A LETTER: "
GoTo !list[%errorlevel%]!




 :299
ENDLOCAL
IF NOT EXIST "*Cover (300 DPI).jpg" GOTO :NullFile
IF EXIST "*Cover (300 DPI).jpg" COPY "c:\Users\admin\Documents\ProgramData\Bin\PricesD Cover - 299.png" "blank12.png"
GOTO :Compile



 :399
ENDLOCAL
IF NOT EXIST "*Cover (300 DPI).jpg" GOTO :NullFile
IF EXIST "*Cover (300 DPI).jpg" COPY "c:\Users\admin\Documents\ProgramData\Bin\PricesD Cover - 399.png" "blank12.png"
GOTO :Compile


 :495
ENDLOCAL
IF NOT EXIST "*Cover (300 DPI).jpg" GOTO :NullFile
IF EXIST "*Cover (300 DPI).jpg" COPY "c:\Users\admin\Documents\ProgramData\Bin\PricesD Cover - 495.png" "blank12.png"
GOTO :Compile


 :599
ENDLOCAL
IF NOT EXIST "*Cover (300 DPI).jpg" GOTO :NullFile
IF EXIST "*Cover (300 DPI).jpg" COPY "c:\Users\admin\Documents\ProgramData\Bin\PricesD Cover - 599.png" "blank12.png"
GOTO :Compile


 :699
ENDLOCAL
IF NOT EXIST "*Cover (300 DPI).jpg" GOTO :NullFile
IF EXIST "*Cover (300 DPI).jpg" COPY "c:\Users\admin\Documents\ProgramData\Bin\PricesD Cover - 699.png" "blank12.png"
GOTO :Compile

感谢大家的帮助。

我会这样做:

@echo off
    cls
        echo/
        echo          A   .99                 H   .99
        echo          B   .99                 I   .99
        echo          C   .95                 J  .95
        echo          D   .99                 K  .95
        echo          E   .99                 L  .95
        echo          F   .99                 M  .95
        echo          G   .95                 N  .95
        echo          ___________________________________
        echo/
        echo                   Press 'Q' to Quit


        echo/
        CHOICE /N /C:abcdefghijklmnq /M "  SELECT A LETTER "

    goto option-%errorlevel%


 :option-1  a299
ECHO a299
GOTO :EOF

IF NOT EXIST "*Cover (300 DPI).jpg" GOTO :NullFile
IF EXIST "*Cover (300 DPI).jpg" COPY "c:\Users\admin\Documents\ProgramData\Bin\PricesD Cover - 299.png" "blank12.png"
GOTO :Compile


 :option-2  b399
ECHO b399
GOTO :EOF

IF NOT EXIST "*Cover (300 DPI).jpg" GOTO :NullFile
IF EXIST "*Cover (300 DPI).jpg" COPY "c:\Users\admin\Documents\ProgramData\Bin\PricesD Cover - 399.png" "blank12.png"
GOTO :Compile

 :option-3  c495
ECHO c495
GOTO :EOF

IF NOT EXIST "*Cover (300 DPI).jpg" GOTO :NullFile
IF EXIST "*Cover (300 DPI).jpg" COPY "c:\Users\admin\Documents\ProgramData\Bin\PricesD Cover - 495.png" "blank12.png"
GOTO :Compile

 :option-14  n4995
ECHO n4995
GOTO :EOF

IF NOT EXIST "*Cover (300 DPI).jpg" GOTO :NullFile
IF EXIST "*Cover (300 DPI).jpg" COPY "c:\Users\admin\Documents\ProgramData\Bin\PricesD Cover - 599.png" "blank12.png"
GOTO :Compile

 :option-15  q
ECHO QUIT

PS - 我不明白关于 "maximum of 9 options in choice command" 的评论。 Choice允许所有数字和字母(大写和小写可能不同)和一些特殊字符作为可能的选项,因此它可能有超过62个不同的选项...

...和一个更简单的方法:

@echo off
setlocal

set "list=299,399,495,599,699,899,995,499,999,1495,1995,2995,3995,4995" 

    cls
        echo/
        echo          A   .99                 H   .99
        echo          B   .99                 I   .99
        echo          C   .95                 J  .95
        echo          D   .99                 K  .95
        echo          E   .99                 L  .95
        echo          F   .99                 M  .95
        echo          G   .95                 N  .95
        echo          ___________________________________
        echo/
        echo                   Press 'Q' to Quit


        echo.
        CHOICE /N /C:abcdefghijklmnq /M "  SELECT A LETTER "

if %errorlevel% equ 15 goto :EOF

for /F "tokens=%errorlevel% delims=," %%a in ("%list%") do set "file=%%a"

echo File: "c:\Users\admin\Documents\ProgramData\Bin\PricesD Cover - %file%.png"