How to open multiple Explorer windows from a batch file

Sometimes you need to open multiple Explorer windows from a batch file. Perhaps because two directories need to be compared by a human, rather than by a computer.

I’ve had to do it multiple times for projects in the past, and so does a longtime reader, who wasn’t able to find how in a Google search.

You might kick yourself after you see how.

Rather than using explorer.exe pathname, use the command start pathname. Here’s an example:

start c:\documents

start e:\backup

Then you’ll get two windows. If you use explorer.exe instead of start, one opens in a window, then the second one immediately opens over the first, in the same window.

Yeah, it’s that simple, though not obvious.

If you want the batch file to pause for human action and then continue afterward, use the pause command. I used to do that when I was staging web servers. Different servers, based on different complex criteria, needed different files. It was easier to just state the rules and let a human place the file rather than try to do it programmatically. Something like this:

echo Drag the right config file to each server. Even-numbered servers get config 1. Odd-numbered servers get config 2, unless they’re a prime number and it happens to be Tuesday, in which case they get config 3.

start “\\server1\c$\config”

start “\\server2\c$\config”

start “\\server3\c$\config”

start “c:\configs”

pause

for %%i in (server1 server2 server3) do xcopy /s c:\webkit “\\%%i\c$”

script continues….

If spaces appear anywhere in the pathname, put them in quotes. They do no harm if they’re unnecessary.

If you like stuff like this, I’ve collected most of my scripting resources in a single post about scripting Windows sysadmin tasks.

2 thoughts on “How to open multiple Explorer windows from a batch file

  • March 19, 2011 at 7:13 pm
    Permalink

    For some reason I don’t remember (long file names?) I had to tweak this a bit.

    New code is

    start explorer “k:\2011_04_01 Install Programs”
    start explorer “k:\2009_08 Install Programs”

    and it works like a charm. Thanks again!

    • March 19, 2011 at 7:27 pm
      Permalink

      Ah, I forgot to mention that. If the filenames have spaces in them, you have to use quotes. Good catch.

      Long filenames are OK without quotes, as long as there are no spaces in them.

Comments are closed.

%d bloggers like this:
WordPress Appliance - Powered by TurnKey Linux