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

**URL:** <https://boards.straightdope.com/t/why-cant-i-cd-to-a-directory-with-a-space-in-it/141676>\
**Category:** Factual Questions\
**Created:** [December 10, 2002, 1:55am UTC](https://boards.straightdope.com/t/why-cant-i-cd-to-a-directory-with-a-space-in-it/141676 "2002-12-10T01:55:10Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cisco](https://avatars.discourse-cdn.com/v4/letter/c/ccd318/32.png) [@Cisco](https://boards.straightdope.com/u/Cisco)\
**Post date:** [December 10, 2002, 1:55am UTC](https://boards.straightdope.com/t/why-cant-i-cd-to-a-directory-with-a-space-in-it/141676/1 "2002-12-10T01:55:10Z")

</div>

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

**cd C:\Program Files**

into [command.com](http://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?

---

<div class="post-metadata">

**Author:** ![kirk](https://avatars.discourse-cdn.com/v4/letter/k/f9ae1b/32.png) [@kirk](https://boards.straightdope.com/u/kirk)\
**Post date:** [December 10, 2002, 2:03am UTC](https://boards.straightdope.com/t/why-cant-i-cd-to-a-directory-with-a-space-in-it/141676/2 "2002-12-10T02:03:07Z")

</div>

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

cd “C:\Program Files”

cd C:\PROGRA~1

---

<div class="post-metadata">

**Author:** ![sleestak](https://avatars.discourse-cdn.com/v4/letter/s/919ad9/32.png) [@sleestak](https://boards.straightdope.com/u/sleestak)\
**Post date:** [December 10, 2002, 2:03am UTC](https://boards.straightdope.com/t/why-cant-i-cd-to-a-directory-with-a-space-in-it/141676/3 "2002-12-10T02:03:42Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Cisco](https://avatars.discourse-cdn.com/v4/letter/c/ccd318/32.png) [@Cisco](https://boards.straightdope.com/u/Cisco)\
**Post date:** [December 10, 2002, 2:05am UTC](https://boards.straightdope.com/t/why-cant-i-cd-to-a-directory-with-a-space-in-it/141676/4 "2002-12-10T02:05:15Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![friedo](https://avatars.discourse-cdn.com/v4/letter/f/8edcca/32.png) [@friedo](https://boards.straightdope.com/u/friedo)\
**Post date:** [December 10, 2002, 2:29am UTC](https://boards.straightdope.com/t/why-cant-i-cd-to-a-directory-with-a-space-in-it/141676/5 "2002-12-10T02:29:21Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Jpeg\_Jones](https://avatars.discourse-cdn.com/v4/letter/j/4bbf92/32.png) [@Jpeg\_Jones](https://boards.straightdope.com/u/Jpeg_Jones)\
**Post date:** [December 10, 2002, 2:31am UTC](https://boards.straightdope.com/t/why-cant-i-cd-to-a-directory-with-a-space-in-it/141676/6 "2002-12-10T02:31:23Z")

</div>

Better yet, get [Open Command Window Here](http://download.microsoft.com/download/whistler/Install/2/WXP/EN-US/CmdHerePowertoySetup.exe), 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.

---

<div class="post-metadata">

**Author:** ![Daver914](https://avatars.discourse-cdn.com/v4/letter/d/4da419/32.png) [@Daver914](https://boards.straightdope.com/u/Daver914)\
**Post date:** [December 10, 2002, 4:42am UTC](https://boards.straightdope.com/t/why-cant-i-cd-to-a-directory-with-a-space-in-it/141676/7 "2002-12-10T04:42:54Z")

</div>

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

cd c:\Program Files

Enjoy,  
Dave

---

<div class="post-metadata">

**Author:** ![ZipperJJ](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/zipperjj/32/211_2.png) [@ZipperJJ](https://boards.straightdope.com/u/ZipperJJ)\
**Post date:** [December 10, 2002, 7:35am UTC](https://boards.straightdope.com/t/why-cant-i-cd-to-a-directory-with-a-space-in-it/141676/8 "2002-12-10T07:35:21Z")

</div>

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”?

---

<div class="post-metadata">

**Author:** ![DarrenS](https://avatars.discourse-cdn.com/v4/letter/d/977dab/32.png) [@DarrenS](https://boards.straightdope.com/u/DarrenS)\
**Post date:** [December 10, 2002, 7:36am UTC](https://boards.straightdope.com/t/why-cant-i-cd-to-a-directory-with-a-space-in-it/141676/9 "2002-12-10T07:36:41Z")

</div>

Also - turn on filename completion. Instructions are [here](http://www.mydesktophelp.com/tips/win04.htm). 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 🙂

---

<div class="post-metadata">

**Author:** ![DarrenS](https://avatars.discourse-cdn.com/v4/letter/d/977dab/32.png) [@DarrenS](https://boards.straightdope.com/u/DarrenS)\
**Post date:** [December 10, 2002, 7:56am UTC](https://boards.straightdope.com/t/why-cant-i-cd-to-a-directory-with-a-space-in-it/141676/10 "2002-12-10T07:56:21Z")

</div>

> [@](#):
>
> \*Originally posted by ZipperJJ \*  
> \*\*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”? \*\*

Yes. If you’re really interested, see the spec [here](http://www.cybertrails.com/~fys/docs/lfnspec.pdf). Section 3.2 explains the mapping of long filenames to short ones.

---

<div class="post-metadata">

**Author:** ![XPav](https://avatars.discourse-cdn.com/v4/letter/x/b77776/32.png) [@XPav](https://boards.straightdope.com/u/XPav)\
**Post date:** [December 10, 2002, 8:23am UTC](https://boards.straightdope.com/t/why-cant-i-cd-to-a-directory-with-a-space-in-it/141676/11 "2002-12-10T08:23:06Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![scr4](https://avatars.discourse-cdn.com/v4/letter/s/59ef9b/32.png) [@scr4](https://boards.straightdope.com/u/scr4)\
**Post date:** [December 10, 2002, 8:31am UTC](https://boards.straightdope.com/t/why-cant-i-cd-to-a-directory-with-a-space-in-it/141676/12 "2002-12-10T08:31:08Z")

</div>

> [@](#):
>
> \*Originally posted by XPav \*  
> **Now I just got to get ls and all my other Linux commands working…**

Have you tried [Cygwin](http://www.cygwin.com/)? 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.)

---

<div class="post-metadata">

**Author:** ![DarrenS](https://avatars.discourse-cdn.com/v4/letter/d/977dab/32.png) [@DarrenS](https://boards.straightdope.com/u/DarrenS)\
**Post date:** [December 10, 2002, 8:36am UTC](https://boards.straightdope.com/t/why-cant-i-cd-to-a-directory-with-a-space-in-it/141676/13 "2002-12-10T08:36:41Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![DarrenS](https://avatars.discourse-cdn.com/v4/letter/d/977dab/32.png) [@DarrenS](https://boards.straightdope.com/u/DarrenS)\
**Post date:** [December 10, 2002, 8:42am UTC](https://boards.straightdope.com/t/why-cant-i-cd-to-a-directory-with-a-space-in-it/141676/14 "2002-12-10T08:42:46Z")

</div>

Sorry - I did mean that post to be informative. I got the utils I use [here](http://www.weihenstephan.de/~syring/win32/UnxUtils.html).

---

<div class="post-metadata">

**Author:** ![wet\_marble](https://avatars.discourse-cdn.com/v4/letter/w/e0b2c6/32.png) [@wet\_marble](https://boards.straightdope.com/u/wet_marble)\
**Post date:** [December 10, 2002, 11:50am UTC](https://boards.straightdope.com/t/why-cant-i-cd-to-a-directory-with-a-space-in-it/141676/15 "2002-12-10T11:50:15Z")

</div>

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

Example:

cd c:\pr\*

---

<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:** [December 10, 2002, 1:53pm UTC](https://boards.straightdope.com/t/why-cant-i-cd-to-a-directory-with-a-space-in-it/141676/16 "2002-12-10T13:53:07Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Kendo](https://avatars.discourse-cdn.com/v4/letter/k/eb9ed0/32.png) [@Kendo](https://boards.straightdope.com/u/Kendo)\
**Post date:** [December 10, 2002, 1:56pm UTC](https://boards.straightdope.com/t/why-cant-i-cd-to-a-directory-with-a-space-in-it/141676/17 "2002-12-10T13:56:45Z")

</div>

> [@](#):
>
> \*Originally posted by wet marble \*  
> \*\*I’m no expert on XP, but on 2000 you can use wildcards in dos.
> 
> Example:
> 
> cd c:\pr\* \*\*

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