prevent the problem of space in windows folders in the command line

12,076

Solution 1

Instead of putting quotes around just part of the path, put quotes around the entire path. If you do that, you should be fine.

start "%cd%\mygame.exe"

Solution 2

In the set command put quotes around the whole assignment:

set "x=%cd%"

In the start command, use quotes as well:

start "%x%\mygame.exe"

Solution 3

for example, if you have a folder name FOO FOO with a space and you want to access from cmd yo just do:

cd "FOO FOO"

That's all

Share:
12,076
shan
Author by

shan

Updated on June 04, 2022

Comments

  • shan
    shan about 2 years

    As we know that windows, we can create folders with a name contains spaces(Hello World,New Folder,My Programs). In the commandline if we use start c:\Hello World\mygame.exe , it gives error called Hello is not found. it split the word from the space, to avoid this we can use thid start c:\"Hello World"\mygame.exe. my problem is this set x=%cd% (Here cd is "c:\Hello World" ) and we execute mygame.exe using this command "start %cd%\mygame.exe" which gives error of Hello is not found. Anyone knows solution for this?

  • shan
    shan about 13 years
    @Brad did u try it with your self?
  • Brad
    Brad about 13 years
    @shan, Yes, I did try it myself, and it works fine for me. If it isn't working for you, did you make sure that you are setting the variable correctly?
  • shan
    shan about 13 years
    @Brad Are u working on windows? What is your cd refer to? if the folder names doesn't any space this works, if there is a spaces this is not work
  • Brad
    Brad about 13 years
    @shan, Yes, I am using Windows, and yes it does work. Try it yourself using %ProgramFiles%. You must be defining %cd% incorrectly.
  • Brad
    Brad about 13 years
    @shan, %cd% is set to the current directory by the system! Why do you need to use it at all? Just call mygame.exe if you are in the correct path.
  • shan
    shan about 13 years
    @Brad because i am not in a working directory,I am try to copy bat file to another location with data.not ProgramFiles Program files.Please give correct answer, when you give the answer,otherwise you are misleading others,Don't ask me to try,I am trying to do it
  • shan
    shan about 13 years
    @Brad In your solution, it only open another console