user3836982 February 2016

Create a BAT file to run multiple file

i need to create a BAT file to run multiple file.File are in the same folder but they have different name and have different parameter. There are some example of file:

.\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

Someone can help me? Thanks all

Answers


npocmaka February 2016

I have no idea what is the logic behind the numbers passed last so I've put them in the iterations list too:

@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 %%~#

)


CoveGeek February 2016

As there is no predictable pattern for the parameters, generating this from a formula looks to be unreliable.

You can build a text file with all the possible parameters sets and just loop through it. For simplicity, make sure that the text file and batch file are in a folder that has no spaces in the path or file name or this command will fail.

The Text File called "Commands.txt" in same folder as batch file:

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

Then in your batch file put the following:

FOR /F %%F IN (%~dp0Commands.txt) DO (
    %~dp0MMDSv1.0.exe %%~F
)

If there are spaces in the path or file use this alternate command:

FOR /F "usebackq tokens=* " %%F IN (`echo "%~dp0Commands.txt"') DO (
    %~dp0MMDSv1.0.exe %%~F
)

The single quote charactors are the back quote which is on the same key as the ~, and the double quotes are the standard quote charactor used in batch files and may be altered by some browsers.


Aacini February 2016

You have shown a list of example file names, but you did not explained how the file names must be processed, so I got my old crystal ball, cleaned it and asked it: "what this problem is about?" and this was the answer:

"Giving a list of file names comprised of several parts separated by underscore and a list of numbers, select a different number as parameter each time that a new file name differs from the previous one in the first three parts".

So this is the solution:

EDIT: After the OP had finally gave us the right method, this is the correct solution:

@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!
)

Post Status

Asked in February 2016
Viewed 1,113 times
Voted 10
Answered 3 times

Search




Leave an answer