[英]Create a BAT file to run multiple file
我需要創建一個BAT文件來運行多個文件。文件位於同一文件夾中,但是它們具有不同的名稱和參數。 有一些文件示例:
.\MMDSv1.0.exe I_30_2_02_02_1.csv 7
.\MMDSv1.0.exe I_30_2_02_02_2.csv 7
.\MMDSv1.0.exe I_30_2_02_02_3.csv 7
.\MMDSv1.0.exe I_30_2_02_02_4.csv 7
.\MMDSv1.0.exe I_30_2_02_04_1.csv 7
.\MMDSv1.0.exe I_30_2_02_04_2.csv 7
.\MMDSv1.0.exe I_30_2_02_04_3.csv 7
.\MMDSv1.0.exe I_30_2_02_04_4.csv 7
.\MMDSv1.0.exe I_30_2_02_06_1.csv 7
.\MMDSv1.0.exe I_30_2_02_06_2.csv 7
.\MMDSv1.0.exe I_30_2_02_06_3.csv 7
.\MMDSv1.0.exe I_30_2_02_06_4.csv 7
.\MMDSv1.0.exe I_30_2_02_08_1.csv 7
.\MMDSv1.0.exe I_30_3_08_02_3.csv 10
.\MMDSv1.0.exe I_30_3_08_02_4.csv 10
.\MMDSv1.0.exe I_30_3_08_04_1.csv 10
.\MMDSv1.0.exe I_30_3_08_04_2.csv 10
.\MMDSv1.0.exe I_30_3_08_04_3.csv 10
.\MMDSv1.0.exe I_30_3_08_04_4.csv 10
.\MMDSv1.0.exe I_30_3_08_06_1.csv 10
.\MMDSv1.0.exe I_30_3_08_06_2.csv 10
.\MMDSv1.0.exe I_30_3_08_06_3.csv 10
.\MMDSv1.0.exe I_30_3_08_06_4.csv 10
.\MMDSv1.0.exe I_30_3_08_08_1.csv 10
.\MMDSv1.0.exe I_30_3_08_08_2.csv 10
.\MMDSv1.0.exe I_50_2_06_08_1.csv 12
.\MMDSv1.0.exe I_50_2_06_08_2.csv 12
.\MMDSv1.0.exe I_50_2_06_08_3.csv 12
.\MMDSv1.0.exe I_50_2_06_08_4.csv 12
.\MMDSv1.0.exe I_50_2_06_10_1.csv 12
.\MMDSv1.0.exe I_50_2_06_10_2.csv 12
有人可以幫我嗎? 謝謝大家
您已經顯示了示例文件名的列表,但是沒有解釋文件名的處理方式,因此我拿到了舊的水晶球,將其清洗並詢問:“此問題是什么?” 這就是答案:
“給出由下划線分隔的幾部分組成的文件名列表和數字列表,每當新文件名與前三個部分中的前一個文件名不同時,就選擇不同的數字作為參數 。”
所以這是解決方案:
編輯 :OP終於給了我們正確的方法后,這是正確的解決方案:
@echo off
setlocal EnableDelayedExpansion
for /F "tokens=1-3* delims=_" %%a in ('dir /B /A-D *.csv') do (
set /A number=%%b*%%c*12/100
MMDSv1.0.exe %%a_%%b_%%c_%%d !number!
)
我不知道最后傳遞的數字背后的邏輯是什么,所以我也將它們放在迭代列表中:
@echo off
for %%# in (
"I_30_2_02_02_1.csv 7"
"I_30_2_02_02_2.csv 7"
"I_30_2_02_02_3.csv 7"
"I_30_2_02_02_4.csv 7"
"I_30_2_02_04_1.csv 7"
"I_30_2_02_04_2.csv 7"
"I_30_2_02_04_3.csv 7"
"I_30_2_02_04_4.csv 7"
"I_30_2_02_06_1.csv 7"
"I_30_2_02_06_2.csv 7"
"I_30_2_02_06_3.csv 7"
"I_30_2_02_06_4.csv 7"
"I_30_2_02_08_1.csv 7"
"I_30_3_08_02_3.csv 10"
"I_30_3_08_02_4.csv 10"
"I_30_3_08_04_1.csv 10"
"I_30_3_08_04_2.csv 10"
"I_30_3_08_04_3.csv 10"
"I_30_3_08_04_4.csv 10"
"I_30_3_08_06_1.csv 10"
"I_30_3_08_06_2.csv 10"
"I_30_3_08_06_3.csv 10"
"I_30_3_08_06_4.csv 10"
"I_30_3_08_08_1.csv 10"
"I_30_3_08_08_2.csv 10"
"I_50_2_06_08_1.csv 12"
"I_50_2_06_08_2.csv 12"
"I_50_2_06_08_3.csv 12"
"I_50_2_06_08_4.csv 12"
"I_50_2_06_10_1.csv 12"
"I_50_2_06_10_2.csv 12"
) do (
.\MMDSv1.0.exe %%~#
)
由於參數沒有可預測的模式,因此從公式生成該模式似乎是不可靠的。
您可以使用所有可能的參數集構建文本文件,然后循環遍歷。 為簡單起見,請確保文本文件和批處理文件位於路徑或文件名中沒有空格的文件夾中,否則此命令將失敗。
與批處理文件位於同一文件夾中的名為“ Commands.txt”的文本文件:
I_30_2_02_02_1.csv 7
I_30_2_02_02_2.csv 7
I_30_2_02_02_3.csv 7
I_30_2_02_02_4.csv 7
I_30_2_02_04_1.csv 7
I_30_2_02_04_2.csv 7
I_30_2_02_04_3.csv 7
I_30_2_02_04_4.csv 7
I_30_2_02_06_1.csv 7
I_30_2_02_06_2.csv 7
I_30_2_02_06_3.csv 7
I_30_2_02_06_4.csv 7
I_30_2_02_08_1.csv 7
I_30_3_08_02_3.csv 10
I_30_3_08_02_4.csv 10
I_30_3_08_04_1.csv 10
I_30_3_08_04_2.csv 10
I_30_3_08_04_3.csv 10
I_30_3_08_04_4.csv 10
I_30_3_08_06_1.csv 10
I_30_3_08_06_2.csv 10
I_30_3_08_06_3.csv 10
I_30_3_08_06_4.csv 10
I_30_3_08_08_1.csv 10
I_30_3_08_08_2.csv 10
I_50_2_06_08_1.csv 12
I_50_2_06_08_2.csv 12
I_50_2_06_08_3.csv 12
I_50_2_06_08_4.csv 12
I_50_2_06_10_1.csv 12
I_50_2_06_10_2.csv 12
然后在您的批處理文件中放入以下內容:
FOR /F %%F IN (%~dp0Commands.txt) DO (
%~dp0MMDSv1.0.exe %%~F
)
如果路徑或文件中有空格,請使用以下替代命令:
FOR /F "usebackq tokens=* " %%F IN (`echo "%~dp0Commands.txt"') DO (
%~dp0MMDSv1.0.exe %%~F
)
單引號字符是與〜相同的鍵上的反引號,而雙引號是批處理文件中使用的標准引號字符,某些瀏覽器可能會更改它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.