创建递增字母序列

问题描述 投票:0回答:1

我想用字母字符替换菜单项的递增数字。

这是我当前的代码:

:begin
@echo off
if exist "%TEMP%\%~n0.tmp" del "%TEMP%\%~n0.tmp"
SET "order=0"
for /f "Tokens=1*" %%A in ('set ^| find /v "Path="') do call :data %%A

:data
set /a "order+=1"
echo [%order%] %1 >>"%TEMP%\%~n0.tmp"
if %order% GEQ 20 goto :_continue
GOTO :eof

:_continue
cls
type "%TEMP%\%~n0.tmp"
rem set "_choice="
rem choice /c %_choice% /m ">...:"
pause & goto :begin

输出为:

[1] ALLUSERSPROFILE
[2] APPDATA
[3] CLINK_DIR
etc...

我想要这样的输出:

[A] ALLUSERSPROFILE
[B] APPDATA
[C] CLINK_DIR
etc...
windows for-loop batch-file cmd
1个回答
0
投票

我知道如何根据@Aacini在此链接上的回答用字母字符替换菜单项的递增数字Incrementing letter in batch-file

这是新代码:


:begin
@echo off
if exist "%TEMP%\%~n0.tmp" del "%TEMP%\%~n0.tmp"
SET "order=64" &rem use ABCD...
for /f "Tokens=1*" %%A in ('set ^| find /v "Path="') do call :data %%A

:data
set /a "order+=1" &rem start with A(65)
set /a "End=65 + 15" &rem max P(65+15)
setlocal enabledelayedexpansion
cmd /C exit %order% & echo [!=ExitCodeAscii!] %1 >>"%TEMP%\%~n0.tmp"
if %order% GEQ %End% goto :makechoices
GOTO :eof

:makechoices
set "_choices="& set "_cho="
for /f "delims=[]" %%C in ('type "%TEMP%\%~n0.tmp"') do set "_cho=!_cho!%%C"
set "_choices= !_cho!z" &rem space to fix "A" choice

:Menu
cls
type "%TEMP%\%~n0.tmp"
echo [Z] ReOpen Script /Refresh
choice /c %_choices:~1% /m "Choices:"
set "_pressed=!_choices:~%errorlevel%,1!"
echo.
echo you pressed [%_pressed%:%errorlevel%]
if "%_pressed%"=="z" start %~nx0 & exit 0
pause & goto :menu

© www.soinside.com 2019 - 2024. All rights reserved.