20

Possible Duplicate:
Using cd Command in Windows Command Line, Can’t Navigate to D:\
CMD cd to other drives except C:\ not working

I am working with cmd.exe on Windows 7 (as opposed to Powershell). I have 2 partitions on my drive, C contains the OS and installed programs, and D contains my data. I was trying to cd from C to D, but cmd wouldn't let me:

C:\>cd D:\

C:\>

However, when I type dir D:\, it will list the contents of D correctly. Why does it do this and how can I fix it? Powershell works fine so I can use that, but I would like to know what makes cmd misbehave.

astay13
  • 333
  • 2
  • 4
  • 10
  • Could someone make an msdos tag? I think this question is valid for all versions of DOS from 1.0 and up. If I recall correctly CP/M didn't have this concept but you could address the separate drives by prepending the driveletter: to the file name. I think this is important as this is a valid question for someone who didn't live through the DOS era and not a Windows 7 question as such. – Stuart Woodward Dec 01 '11 at 00:31
  • @StuartWoodward actually DOS 1.0 did not have subdirectories - they were introduced in 2.0. – Jesse Slicer Dec 02 '11 at 18:31

3 Answers3

33

You have to use just d: , not cd d:\

EDIT: it is also possible to use cd /d d: to change drives using cd

soandos
  • 24,206
  • 28
  • 102
  • 134
  • I am not really sure why made that design decision, and I am looking for it, but that's just the way that it has always been. – soandos Nov 27 '11 at 01:41
  • @astay13 see edit. – soandos Nov 27 '11 at 01:42
  • 1
    @soandos `cd` stands for "change directory", and `D:` is a drive, not a directory. See David's answer for more details – Izkata Nov 27 '11 at 05:56
  • @Izkata why cant you change to a directory on a different drive using the same syntax used to go to a different folder? that is what I was saying. – soandos Nov 27 '11 at 05:58
  • It does change the directory: e.g.: C:\>cd D:\test, does change the current directory on disk D: to test, but the prompt is still on C: – Sebastian Godelet Nov 27 '11 at 10:34
  • @soandos The only advantage to this scheme is that sometimes it is convenient to have a working directory on more than one drive. For example, if you're trying to copy files from c:\ to d:\ you can go to drive D, cd to the long path, then go to drive C, cd to the long path, and then just copy to 'D:'. Then you can go back to drive D and cd relative to the long path without retyping it. – David Schwartz Nov 27 '11 at 22:46
  • You can't really ask why DOS works the way it does. It provided the minimum set of commands to manage your files without wasting space on your 16K of memory or 160K floppy drive. – Stuart Woodward Dec 01 '11 at 00:38
28

Windows tracks a separate working directory for each drive. You are currently on the 'C' drive in the working directory '\'. When you type cd d:\ it changes your working directory for the 'D' drive to '\' and has no effect on your C drive working directory. To change drives, just type D:. You can change both at the same time with the /d parameter to cd.

David Schwartz
  • 61,528
  • 7
  • 100
  • 149
  • 3
    Actually, the Windows that the questioner says that xe is running — Windows NT 6.1 — has _never_ — not since 1993 — had a separate working directory for each drive. There is _one_ working directory per process. The _appearance_ of multiple working directories across multiple drives is a fiction maintained by Microsoft's command interpreter and the runtime libraries of its languages, using hidden environment variables. – JdeBP Nov 27 '11 at 20:33
  • 1
    [Obligatory vaguely-related link to Old New Thing](http://blogs.msdn.com/b/oldnewthing/archive/2010/10/11/10073890.aspx) – u1686_grawity Nov 29 '11 at 20:05
  • @JdeBP Hidden environment variables that track a separate working directory for each drive? And is Microsoft's command interpreter and the runtime libraries of its languages part of Windows? – David Schwartz Feb 02 '16 at 20:07
1

It should be noted that pushd (e.g. pushd D:\) will always change drives.

bobbymcr
  • 2,182
  • 1
  • 14
  • 14