Open a file with spaces from batch file?

Registration date
Saturday July 26, 2008
Last seen
July 27, 2008
 vongsi -
I have made a batch file that will ask you what file name you want to open and what directory it's in.
The only problem is that I can't open files with spaces in the name because it treats the first word as the whole file.
Can someone help me?
Here's the code:

@echo off
echo Change directory?
set /p "cho=>"
if %cho%==y goto Change
if %cho%==Y goto Change
if %cho%==n goto Open
if %cho%==N goto Open
echo That's not a valid choice, dumbass.
goto CD
echo What would you like to open? (Name and Extension) Or type "End" to exit.
set /p "n=>"
if %n%==End goto End
if %n%==end goto End
if %n%=="End" goto End
if %n%=="end" goto End
start %n%
goto Open
goto End
echo Enter the desired directory.
set /p "x=>"
goto Open

Placing quotes around the input variables opens up another cmd window for some reason...

4 replies

Hi Korra,

the problem with quotes appears for the follwing reason:

syntax of START

START ["title"] [path]

It treats the string in quotes as a title of the new cmd window. So, you may do the following:

START "" "path"

First quotes will be treated as a title and second will be treated as a path.

Hope this helps.
Thank you

A few words of thanks would be greatly appreciated. Add comment

CCM 2942 users have said thank you to us this month

The simplist solutions are always the most obvious...thank you
thank you, been looking for this in a million websites
thank you it helped alot :)
30-10-2017 - It helped me, Thanks a lot
Dear frnds,
I know you all suffering from the problem of space in .bat file...
Here is the solution...
Use " " (doublequote space doublequote) instead of space..your problem will be solved...
It worked on my machine..
If you are satisfied with this information..plz let me know on my id
surround file name with double quotes
Short & Sweet Answer. Thanks. Shrawan.
> anonymous
great answer!! thanks!!
Thanks for taking the time to answer!
thaks. my problem has also solved
Hello Korra,
I want to open multiple files with the same extention with a batch file. Can you please send me your batch file or let me know how to create it? I've written one and it works partially. My email address is