Despite the answers giving the illusion that it works, the fact is you can't sneak in spaces into usual cmd arguments. This is easy to prove:
Save "echo %1
" as test.bat
. This batch file will output the first argument which cmd passes us.
Now, try and run test.bat
, setting the value of %1
to foo bar
. (Note that there's a space char between foo
and bar
.)
Trial-and-error for a few years and realize that there's no way to do it. Folks will suggest to escape using ^
, yet test.bat foo^ bar
will not output foo bar
.
So, there's no way to get the output foo bar
, and the closest we can get is running test.bat foo" "bar
which produces foo" "bar
, or running test.bat "foo bar"
which produces "foo bar"
.
Now, the reason the other answers appear to work is because cd
does it's own additional parsing, diverging from the behavior of usual argument passing (the usual %1
, %2
, %3
and etc in typical batch files).
For example, consider the peculiar command:
cd c:\documents and settings \some folder with spaces
Why does it work? This is due to cd
itself doing something equivalent of joining the 7 usual arguments into one logical one. According to cmd argument passing norms, we see 7 arguments:
c:\documents
and
settings
\some
folder
with
spaces
It's as though cd
has joined all the 7 arguments into one logical one, doing something akin to array.join(" ")
, which produces the path:
c:\documents and settings \some folder with spaces
Note that this behavior is peculiar to cd
only (and some other functions). It has nothing to do with usual argument passing.
Indeed, cd
has another peculiarity. Remember we stated above that we couldn't get the output foo bar
? The closest output we can get is by running:
test.bat foo" "bar
which produces foo" "bar
, or:
test.bat "foo bar"
which produces "foo bar"
, or:
test.bat "foo "bar
which produces "foo "bar
, or:
test.bat foo" bar"
which produces foo" bar"
, or:
test.bat "foo b"ar
which produces "foo b"ar
, or:
test.bat fo"o bar"
which produces fo"o bar"
, or:
test.bat fo"o ba"r
which produces fo"o ba"r
, or:
test.bat "fo"o" bar"
which produces "fo"o" bar"
, or:
test.bat "f""o""o"" ""b""a""r":
which produces "f""o""o"" ""b""a""r"
, or even:
test.bat """"f"""o""""o"" ""ba"""r"""""""""":
which produces """"f"""o""""o"" ""ba"""r""""""""""
.
All the above examples have one similarity, which is they'll produce foo bar
after we trim off the "
chars. cd
's author must have realized this too... if we were to infer from cd
's peculiar behavior which trims off all "
it receives, allowing all of these commands to work:
cd c:\documents and settings
cd "c:\documents and settings"
cd "c:"\"documents and settings"
cd c:\"documents" "and" "settings"
cd c:\"docu"ments an"d set"tings"
cd c:"\"docu"ments an"d set"ti"""ngs
cd "c"":""\"docu"ments an"d set"ti"""ngs
cd "c"":""\"do""cu"me"nts a"n""d set"ti"""ngs
cd c"""":""""\"""d"""oc""""u"me"""""nt"s a"n""d set"""""""ti""""ngs
2you meant you have a good reason for 'not' wanting to use quotation marks. – Thomas – 2011-05-04T12:56:26.663
Why, is your quotation mark key broken? :) – slhck – 2011-05-04T12:57:37.283
@Thomas well spotted! – David – 2011-05-04T13:04:34.863
3@slhck Don't worry my shift key and number 2 key are perfectly ok! I'm using a command that doesn't appear to allow wildcards when they apear inside quotation marks thats all! – David – 2011-05-04T13:06:50.277
have you tried SVN add "c:\Documents and Settings\username\svn". ? – KutscheraIT – 2011-05-04T13:45:53.300
Have you tried
SVN add "c:\Documents and Settings\username\svn\"*.*
orSVN add "c:\Documents and Settings\username\svn"\*.*
? – Mark Booth – 2011-05-04T13:48:16.4031@MarkBooth and @WeltenWanderer nice try but unfortunately this doesn't work. In all 3 cases I get an "svn: Error resolving case of ....." – David – 2011-05-04T14:00:24.270
Trying to work around the problem, you could use junctions (http://en.wikipedia.org/wiki/NTFS_junction_point) to create paths without spaces in them.
– Mark Booth – 2011-05-04T14:13:27.4731Have you tried old 8.3 formatting of the name ( DOCUME~1 )? – Justin Pearce – 2011-05-04T15:11:33.287
Just to be pedantic, you don't need quotes with
cd
, even when there are spaces in the path. Couldn't you just usecd
and then make a temporary %variable% from it, and use that? – paradroid – 2011-05-04T17:35:10.223