10

I have a Java program working with this syntax:

command.jar namefile

I have to run this program for 1600 files in a directory. How can I run this command for every file automatically?

Is there a DOS batch command? Or another way?

1 Answer 1

15

The easiest way is by far to simply run a for loop over all the files. The good thing is that the set (the input for the for-loop) does accept the same wildcards like the regular cmd.

For use in a batch file:

FOR %%f IN (*) DO command.jar %%f

For use from the command line:

FOR %f IN (*) DO command.jar %f
3
  • Hi! It works with this: for %f in (*) do command.jar %f Really really thanks! :)
    – E_M
    Mar 5, 2010 at 9:03
  • @E_M: Edited my answer to make that clear.
    – Bobby
    Mar 5, 2010 at 9:03
  • This is because you have to escape the % in a batch file. To be safe you should first append 'echo' to the beginning of the command to see what exactly will be executed.
    – mrexodia
    Sep 23, 2018 at 15:12

You must log in to answer this question.