Open a file with spaces from batch file? [Solved/Closed]

Branflakes91093 1 Posts Saturday July 26, 2008Registration date July 27, 2008 Last seen - Jul 27, 2008 at 02:46 PM - Latest reply:  vongsi
- Oct 30, 2017 at 12:22 AM
Hello,
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:

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

Placing quotes around the input variables opens up another cmd window for some reason...
Thanks.
See more 
1Posts Saturday July 26, 2008Registration date July 27, 2008 Last seen

17 replies

+30
Helpful
8
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.
Was this answer helpful?  
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
+16
Helpful
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
+6
Helpful
5
surround file name with double quotes
Short & Sweet Answer. Thanks. Shrawan.
Korra > anonymous - Feb 1, 2010 at 08:39 AM
great answer!! thanks!!
Thanks for taking the time to answer!
thaks. my problem has also solved
0
Helpful
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 u3185168@anu.ed.au.
Thanks
Housh