Why can't I CD to a directory with a space in it?

All my friends are doing it!
Using XP on NTFS, I type:

cd C:\Program Files

into command.com and get:

Too Many Parameters - Files

So I try it without the space - Invalid Directory

So I try it with %20 (I knew this was a longshot) - Invalid Directory

What in the world is going on here? How do they expect me to get to any directories with spaces in them?

Put it in double qoutes or use the short file name.

cd “C:\Program Files”

cd C:\PROGRA~1

Try this

cd c:
dir /p

Which will list all the directories on the drive by page. Then copy the exact directory name down and try it again. It may look like this

cd c:\progra~1

BTW, this could be wrong. I rarely use XP

Slee

Aha, thank you :). The quotes didn’t work but the short filename did. Don’t know why I didn’t think of that.

How about sticking a \ before the space? That works in your typical Unix shell, don’t know about DOS though.

Better yet, get Open Command Window Here, which is a small utility offered by Microsoft that allows you to right click on any directory in Windows Explorer and open a command window at that directory.

n.b. This utility only works for Windows XP.

If you’re using Windows XP, there’s another option. Instead of using moldy old command.com, use the NT command interpreter, cmd.exe. Just type cmd into a run window instead of command.com. This lets you enter long directory names as normal, i.e:

cd c:\Program Files

Enjoy,
Dave

Quick question -

When you use the short file name, how does the comp know the difference between PROGRAM FILES and PROGRAMS? Does the ~1 mean “first alphabetically”?

Also - turn on filename completion. Instructions are here. Usual disclaimers about editing the Registry may cause you to turn purple and explode etc. etc. Then, when in the command prompt, start typing the name of the folder and hit <TAB>.

cd c:\pr<TAB>

will probably be enough.

I love command line completion - yes, I know Linux has it too :slight_smile:

Yes. If you’re really interested, see the spec here. Section 3.2 explains the mapping of long filenames to short ones.

Command line completion for 2k/XP?

Now I just got to get ls and all my other Linux commands working and I won’t have to take twice as long on the rare occasions I fire up the command prompt.

Have you tried Cygwin? It’s a unix environment that works under Windows. It looks like you can use it as a “Bash for Windows” with all the usual GNU tools. (I haven’t played around with it much yet.)

XPav - I have my Windows system set up with pretty much all the common Linux/Unix commands. I happily switch back and forth between the warm and fuzzy Windows GUI, and the cold but efficient command line utilities like ‘grep’, ‘rm’, ‘cut’ et al.

Sorry - I did mean that post to be informative. I got the utils I use here.

I’m no expert on XP, but on 2000 you can use wildcards in dos.

Example:

cd c:\pr*

You can also drag-and-drop files and folders from Windows Explorer into a command window and it will fill in the complete path. This can save a lot of typing if the items in question are several directories deep.

Woo-hoo! This works in XP too - thanks ever-so, wet marble.