2017-10-20 69 views
1

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

下面的代码是我目前:

@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 
+0

至少可以帮助你''Rem'ark你的脚本,以便我们知道每行代码的目的是做什么。在你的代码要求'Y'或'N'作为输入的时候,这意味着'%resp%'会做一个递归的'Dir'寻找一个名为'Template_VBAForm * Y * .xlsm'或者'Template_VBAForm * N * .xlsm'。 '2'&'3'行实际上什么都不做,这是用意吗? – Compo

+0

@Compo请看我编辑的代码。我偶然输入了测试代码。 – 1QuickQuestion

+0

你实际上在说,这是一些代码,它不会做我想做的事情,我也没有试图改变它!我建议你使用'for'循环来运行'dir',将结果文件名保存为变量并将它们输出为顺序编号的列表。 – Compo

回答

2

这里有一个简单的例子,也许你开始。

@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 
相关问题