.bat-从文件夹文件列表创建菜单 [英] .bat - Create a menu from folder file list

查看:136
本文介绍了.bat-从文件夹文件列表创建菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通常不创建.bat文件,但我将此小脚本用于开发.

I don't usually create .bat file, but I made this little script useful for develop.

我正在使用它来读取和创建文件夹中包含的文件列表:

I'm using this for reading and creating a list of files contained into a folder:

for /f "delims=|" %%f in ('dir /b C:\src\release\android\') do echo %%f

,我发现了有关如何从文件列表开始创建菜单的信息-> 批处理文件上的多项选择菜单?

and I found this about how to create a menu starting from a list of file -> Multiple choices menu on batch file?

现在我的问题是:

我想创建一个菜单,其中包含该文件夹中包含的文件的列表,我可以通过按列表中的相对编号来选择(而不是多项选择),但是我真的不知道如何合并两者上面的代码.

I'd like to create a menu with a list of files contained into that folder which I can select (not multiple selection) by pressing it's relative number on the list, but i don't really know how to merge the two bit of code above.

最终结果应类似于:

[1] ..
[2] ..
[3] ..
[4] ..

select file: 

,它将安装从文件夹中选择的文件.

and it will install the selected file from the folder.

任何建议将不胜感激.

预先感谢

推荐答案

除非您使用的Windows版本没有choice,例如您出于某种原因仍在使用XP,否则此方法应该起作用.

This should work unless you're using a version of Windows that doesn't have choice, like if you're still on XP for some reason.

@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%]!"

这篇关于.bat-从文件夹文件列表创建菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆