How to use a path with spaces in the batch file? [duplicate]

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

2 Answers

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

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

You Might Also Like