4

I have a simple Win 10 batch script to open a bunch of folders within Explorer at system startup, however there's a problem with the last command's path containing whitespaces, as instead of opening a new Explorer window as expected, it opens a CMD window with the path as a system command:

@ECHO OFF
start C:\Users\Darek\Fallout2
start C:\Users\Darek\Fallout2\data\scripts
start C:\Users\Darek\Pobrane_2
start "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC"

How do I write the last command so it works correctly?

1
17

The issue is that the start command (built into CMD) has a special way to handle the first parameter with quotation marks, which is to specify an optional title for the created window; without the first set of quotation marks (like the solution below), the start command is interpreting the command shown in the question as follows:

  1. Create a window with a title of:
    C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC
    
  2. No information is provided on what to actually start in that window

The solution is to run:

start "" "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC"

:: # Or more elaborately:
start "Optional Window Title" "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC"
3
  • Thx., this actually work. Another metchod I just have discovered is to create a non-space including shortcut and to pass the shortcut name to start command! – Mulligan Jun 13 at 10:41
  • 14
    "has a special way to handle the first parameter with quotation marks". That's... evil. – RonJohn Jun 13 at 21:53
  • @RonJohn that's one of the nasty things left from 16-bit Windows era. There were no long file name support there so if start sees a " then it assumes that's a window title. It's impossible to fix, so just avoid cmd nowadays and use powershell instead – phuclv Jun 14 at 6:40
0

You can start explorer.exe with a path; it will open a new window displaying the specified path. If a non-existing path is given, explorer will default to displaying the user's My Documents folder

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