我通常不创建 .bat 文件,但我制作了这个对开发有用的小脚本。
我正在使用它来读取和创建包含在文件夹中的文件列表:
for /f "delims=|" %%f in ('dir /b C:\src\release\android\') do echo %%f
我发现这个关于如何从文件列表开始创建菜单 -> Multiple choices menu on batch file?
现在我的问题是:
我想创建一个菜单,其中包含该文件夹中包含的文件列表,我可以通过按列表中的相对编号来选择(不是多项选择),但我真的不知道如何合并两者上面的一些代码。
最终结果应该是这样的:
[1] ..
[2] ..
[3] ..
[4] ..
select file:
它将从文件夹中安装选定的文件。
如有任何建议,我们将不胜感激。
提前致谢
最佳答案
这应该有效,除非您使用的 Windows 版本没有选择
,例如如果您出于某种原因仍在使用 XP。
@echo off
setlocal enabledelayedexpansion
set count=0
set "choice_options="
for /F "delims=" %%A in ('dir /a:-d /b C:\src\release\android\') do (
REM Increment %count% here so that it doesn't get incremented later
set /a count+=1
REM Add the file name to the options array
set "options[!count!]=%%A"
REM Add the new option to the list of existing options
set choice_options=!choice_options!!count!
)
for /L %%A in (1,1,!count!) do echo [%%A]. !options[%%A]!
choice /c:!choice_options! /n /m "Enter a file to load: "
:: CHOICE selections get set to the system variable %errorlevel%
:: The whole thing is wrapped in quotes to handle file names with spaces in them
:: I'm using type because I'm not familiar with adb, but you be able to get the idea
type "C:\src\release\android\!options[%errorlevel%]!"
关于windows - .bat - 从文件夹文件列表创建菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30592253/