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?

JW0914
  • 7,052
  • 7
  • 27
  • 48
Mulligan
  • 669
  • 3
  • 11
  • 30
  • 1
    duplicates: [Can I use the “start” command with spaces in the path?](https://superuser.com/q/239565/241386), [Weird behavior when launching app from CMD with/without start](https://superuser.com/q/758870/241386), [How do I actually open a program from a batch file? All it does is open a command prompt with that file name](https://superuser.com/q/587131/241386)... – phuclv Jun 14 '21 at 06:38

2 Answers2

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"
JW0914
  • 7,052
  • 7
  • 27
  • 48
TOOGAM
  • 15,243
  • 4
  • 41
  • 58
  • 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 '21 at 10:41
  • 14
    "has a special way to handle the first parameter with quotation marks". That's... evil. – RonJohn Jun 13 '21 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 '21 at 06: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

CSM
  • 1,164
  • 8
  • 8