Let's say I have 20,000 BAT files, and I want to execute them all in one shot. But instead of typing line after line: "Start/Call file1.bat...." "Start/Call file2.bat...." "Start/Call file3.bat...."

Is there a quicker way I can execute all 20,000 bat files with one command? If you wanted to execute all files in a folder in Linux, you would use the command: ./(path)/*

  • 3
    Consider using a pause or some sort of delay too if you have load issues on the machine running the 20k scripted processes. – Formerly Pimp Juice IT Jun 12 '19 at 1:01
  • @PimpJuiceIT Is there a system out there that won't fall over with 20,000 jobs starting all at once? That's an awful lot of memory that will be demanded. – Loren Pechtel Jun 12 '19 at 3:21
  • 1
    The OP did not say they should start all at once - he said with one command. I imagine he would want them to run consecutively. – davidgo Jun 12 '19 at 4:51

Running ./(path)/* won't work on Linux, either -- it will just run the first one and pass the rest of them as parameters to it. You need to use a loop.

On Linux that would be, e.g.:

for i in path/* ; do $i ; done

The equivalent on Windows batch is, if you run it on the commandline:

for %i in (path\*) do @call %i

Or if you put it inside a batch file:

for %%i in (path\*) do @call %%i

You will run into issues with the length of the command if you have 20,000 files, so you might need a different scheme for iterating over them. If they are all numbered sequentially, you could just iterate the numbers.

| improve this answer | |
  • 2
    Using call or start tho for Windows batch scripts and maybe consider using some variable substitutions specifying the full path and batch script file names explicitly and double quoted. – Formerly Pimp Juice IT Jun 12 '19 at 1:00
  • 1
    Regarding your last paragraph about "length of the command". Not sure what you mean. If you mean time to execute 20,000 files, yes that is a concern, but iterating numbers wouldn't make it any faster. If you mean the number of bytes in the command line, then no, that is not an issue. – dbenham Jun 12 '19 at 14:13
  • @dbenham On Linux (bash) there is a limit to the length, as the file names are actually expanded into the command, but yes, on Windows it behaves differently. – vlumi Jun 12 '19 at 23:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.