windows - 尝试创建批处理文件以选择要打开的文件

标签 windows batch-file variables cmd

我正在尝试创建一个批处理文件,按名称搜索特定系列的文件,并创建一个列表来选择要运行/打开的文件。我的问题是我不知道如何将每个结果设置为一个变量。

下面的代码是我目前拥有的:

@echo off
::The code below requests for the user to enter part of the file name
::that he/she is interested in opening. This either provides a file name
::or provides a list of similar file names. I would like to take the list
::and create a numbered list from the user can select by entering the 
::associated number.
echo Please enter part of the file name that you would like to search for.
set INPUT=%input%
set /P INPUT=Type input: %=%
dir Template_VBAForm*%INPUT%*.xlsm /b /s

pause

最佳答案

这里有一个简单的示例,或许可以帮助您入门。

@Echo Off
Set/P "INPUT=Please enter your part file name search term: "
Set "resp=Where/R .\ "Template_VBAForm*%INPUT%*.xlsm""
Set "i=0"
For /F "Delims=" %%A In ('%resp%') Do (Set/A "i+=1"
    Call Set "[%%i%%]=%%A")
Set [||GoTo EndIt
Set/P "INPUT=Please enter an item number: "
If Defined [%INPUT%] Call Echo %%[%INPUT%]%%
:EndIt
Pause

关于windows - 尝试创建批处理文件以选择要打开的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46854922/

相关文章:

html - 使用 Python 单击 HTML 页面上的某些链接时如何打开 Windows 文件夹

linux - 跨平台控制台清算?

node.js - 在Windows上运行 Electron

java - 如何限制 JPA Batch 查询的内存使用?

windows - 在 Windows 中以其子项也被杀死的方式杀死批处理文件

c - 在方法头中后缀变量类型的星号有何意义?

node.js - Node.js 中的应用程序范围变量?

php - 从 MySQL 查询填充组合框的值字段

windows - 在Server Core 2019上对本地帐户使用Power Shell Remoting时访问被拒绝

windows - 在 Windows 中使用脚本添加代理设置异常(exception)