Open a file with spaces from batch file?

Solved/Closed
Branflakes91093 Posts 1 Registration date Saturday July 26, 2008 Status Member Last seen July 27, 2008 - Jul 27, 2008 at 02:46 PM
 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.
Related:

4 responses

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.
38
Thanks a lot
It completely solved the problem I was facing in which a cmd window pops up instead of the desired application
0
Thanks, it helped me as well. :)
0