DOS(like) batch file issue

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.

Put quotes around the directory name.


md “dir name”

Thanks. I tried single quotes, and it failed.

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.

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.

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.

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. :smiley:

(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.

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

To add to the quote/backslash tips and give a more helpful answer, I think the OP should read Microsoft’s cmd documentation, 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…

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.