2017-10-20 71 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 
相關問題