# DOS(like) batch file issue

**URL:** <https://boards.straightdope.com/t/dos-like-batch-file-issue/516085>\
**Category:** Factual Questions\
**Created:** [November 2, 2009, 7:01pm UTC](https://boards.straightdope.com/t/dos-like-batch-file-issue/516085 "2009-11-02T19:01:43Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![VunderBob](https://avatars.discourse-cdn.com/v4/letter/v/839c29/32.png) [@VunderBob](https://boards.straightdope.com/u/VunderBob)\
**Post date:** [November 2, 2009, 7:01pm UTC](https://boards.straightdope.com/t/dos-like-batch-file-issue/516085/1 "2009-11-02T19:01:43Z")

</div>

Is there a way to create a directory that has a space character in the name string using a DOS command like md?

I don’t see any flags with the md command that allows for creating references that contain space characters, although by experimentation, I can use cd to get to such a directory.

I know I can do it with compiled code and Windows directory routines, but the problem as given to me dictates a batch file/command method.

---

<div class="post-metadata">

**Author:** ![engineer\_comp\_geek](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/engineer_comp_geek/32/504_2.png) [@engineer\_comp\_geek](https://boards.straightdope.com/u/engineer_comp_geek)\
**Post date:** [November 2, 2009, 7:05pm UTC](https://boards.straightdope.com/t/dos-like-batch-file-issue/516085/2 "2009-11-02T19:05:26Z")

</div>

Put quotes around the directory name.

---

<div class="post-metadata">

**Author:** ![pan1](https://avatars.discourse-cdn.com/v4/letter/p/e495f1/32.png) [@pan1](https://boards.straightdope.com/u/pan1)\
**Post date:** [November 2, 2009, 7:07pm UTC](https://boards.straightdope.com/t/dos-like-batch-file-issue/516085/3 "2009-11-02T19:07:28Z")

</div>

yep:  
example:

md “dir name”

---

<div class="post-metadata">

**Author:** ![VunderBob](https://avatars.discourse-cdn.com/v4/letter/v/839c29/32.png) [@VunderBob](https://boards.straightdope.com/u/VunderBob)\
**Post date:** [November 2, 2009, 7:14pm UTC](https://boards.straightdope.com/t/dos-like-batch-file-issue/516085/4 "2009-11-02T19:14:03Z")

</div>

Thanks. I tried single quotes, and it failed.

---

<div class="post-metadata">

**Author:** ![xash](https://avatars.discourse-cdn.com/v4/letter/x/c6cbf5/32.png) [@xash](https://boards.straightdope.com/u/xash)\
**Post date:** [November 2, 2009, 7:38pm UTC](https://boards.straightdope.com/t/dos-like-batch-file-issue/516085/5 "2009-11-02T19:38:19Z")

</div>

Use Alt-255. Only thing is to cd into it, you would need to use Alt-255 where the space is otherwise it won’t cd.

---

<div class="post-metadata">

**Author:** ![control-z](https://avatars.discourse-cdn.com/v4/letter/c/eada6e/32.png) [@control-z](https://boards.straightdope.com/u/control-z)\
**Post date:** [November 2, 2009, 8:27pm UTC](https://boards.straightdope.com/t/dos-like-batch-file-issue/516085/6 "2009-11-02T20:27:23Z")

</div>

And suppose you have a directory name like “Scary Movies” To save typing you can type:

cd scary\*

Recent versions of Windows (XP and up I believe) will automatically search for the first directory that begins with “scary” and change to that.

---

<div class="post-metadata">

**Author:** ![ftg](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/ftg/32/2801_2.png) [@ftg](https://boards.straightdope.com/u/ftg)\
**Post date:** [November 2, 2009, 9:28pm UTC](https://boards.straightdope.com/t/dos-like-batch-file-issue/516085/7 "2009-11-02T21:28:09Z")

</div>

> [@control-z](#):
>
> And suppose you have a directory name like “Scary Movies” To save typing you can type:
> 
> cd scary\*
> 
> Recent versions of Windows (XP and up I believe) will automatically search for the first directory that begins with “scary” and change to that.

Or you can hit “tab” after the first few chars and it will cycle thru all files or dirs that have that prefix. It even throws in the quote marks for free.

---

<div class="post-metadata">

**Author:** ![Number](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/number/32/242_2.png) [@Number](https://boards.straightdope.com/u/Number)\
**Post date:** [November 3, 2009, 3:29am UTC](https://boards.straightdope.com/t/dos-like-batch-file-issue/516085/8 "2009-11-03T03:29:25Z")

</div>

Just for the sake of over-completeness, you can also drag-and-drop the folder onto the command window and it will fill in the full path, including quotes if necessary.

This works on any Windows except for Vista and Server 2008, where Microsoft broke it for no good reason. On those you have to shift-right click and hit Copy As Path.

Drag-and-drop is apparently back in 7.

---

<div class="post-metadata">

**Author:** ![Digital\_Stimulus](https://avatars.discourse-cdn.com/v4/letter/d/aeb1de/32.png) [@Digital\_Stimulus](https://boards.straightdope.com/u/Digital_Stimulus)\
**Post date:** [November 3, 2009, 6:29am UTC](https://boards.straightdope.com/t/dos-like-batch-file-issue/516085/9 "2009-11-03T06:29:08Z")

</div>

> [@VunderBob](#):
>
> I know I can do it with compiled code and Windows directory routines, but the problem as given to me dictates a batch file/command method.

An idea: you could install cygwin and either utilize the cygpath utility or just stick with bash and revel in all the unix-y goodness. 😃

(Yes, I realize it wouldn’t really help with resolving the space and quotemark issues. I’m mostly kidding…but if the major requirement is to use “a command method”, I’m just proposing an out-of-the-box solution. Again: :D)

---

<div class="post-metadata">

**Author:** ![BigT](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/bigt/32/12044_2.png) [@BigT](https://boards.straightdope.com/u/BigT)\
**Post date:** [November 4, 2009, 3:48am UTC](https://boards.straightdope.com/t/dos-like-batch-file-issue/516085/10 "2009-11-04T03:48:59Z")

</div>

> [@Digital\_Stimulus](#):
>
> An idea: you could install cygwin and either utilize the cygpath utility or just stick with bash and revel in all the unix-y goodness. 😃
> 
> (Yes, I realize it wouldn’t really help with resolving the space and quotemark issues. I’m mostly kidding…but if the major requirement is to use “a command method”, I’m just proposing an out-of-the-box solution. Again: :D)

And you can use quotes in bash. I didn’t learn the whole backslash thing until much later.

---

<div class="post-metadata">

**Author:** ![Digital\_Stimulus](https://avatars.discourse-cdn.com/v4/letter/d/aeb1de/32.png) [@Digital\_Stimulus](https://boards.straightdope.com/u/Digital_Stimulus)\
**Post date:** [November 4, 2009, 6:19am UTC](https://boards.straightdope.com/t/dos-like-batch-file-issue/516085/11 "2009-11-04T06:19:43Z")

</div>

> [@BigT](#):
>
> And you can use quotes in bash.

Both single and double quotes (in pairs, of course). Embedded within each other, even.

> [@](#):
>
> I didn’t learn the whole backslash thing until much later.

To add to the quote/backslash tips and give a more helpful answer, I think the OP should read Microsoft’s [cmd documentation](http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/chdir.mspx?mfr=true), particularly the part about command extensions ~1/2 way down the linked page (turned on and off using the **/e: on** and **/e: off** switches). And there’s a full description on using quote marks, which isn’t always as straightforward as it (seems it) should be…

---

<div class="post-metadata">

**Author:** ![Waffle\_Decider](https://avatars.discourse-cdn.com/v4/letter/w/77aa72/32.png) [@Waffle\_Decider](https://boards.straightdope.com/u/Waffle_Decider)\
**Post date:** [November 4, 2009, 1:04pm UTC](https://boards.straightdope.com/t/dos-like-batch-file-issue/516085/12 "2009-11-04T13:04:00Z")

</div>

More useless trivia: On the Windows command line, the caret character (^) is sort of the moral equivalent of the backslash on Unix. So, you can also do

cd Scary^ Movies

instead of

cd “Scary Movies”

It can also be used to escape the quote character when passing command line arguments to programs. However, there’s some goofiness in how it is interpreted and it’s not exactly like how backslash works on Unix. For example, while I know that it works with cd for sure, mkdir doesn’t seem to understand it.
