Why doesn't "cd D:" change the command context to D:? [duplicate]

Possible Duplicate:
Using cd Command in Windows Command Line, Can't Navigate to D:\

Every time I want to change directory context to another drive (D, E, F, or whatever..) on a Windows command-prompt, I must use "Drive letter":\ command to actually change it. If I try with "cd command" on cd H:\ it just echo H:\ for me and do nothing:

Enter image description here

Is there some reason for such a behavior? I mean, shoudn't cd command work to do this? Why does't it?


Try:

cd /d d:

/d will also switch drive letters as well as directories, for other information, see cd /?


The reason Windows behaves this way, is because DOS behaved that way.

In DOS, each drive has its own current directory, and the cd command changes the current directory on a drive. If that also happens to be the current drive, then your working directory changes along with it. If you want to change the current drive, you simply specify the drive letter as a command.

Notes that Windows doesn't actually work this way anymore -- you only have one current directory at any time -- but the command shell goes to great lengths to pretend that there are still per-drive current directories. Presumably this is to preserve compatibility with existing DOS batch files.

The reason DOS works this way dates back to the very earliest versions of DOS, and CP/M before it. The gory details can be found on Raymond Chen's blog.


The straight-forward answer is that "because it is not written to work that way". Simply entering D: will do what you want.

Curiously entering cd D:\somedir will, in fact, change the current directory on D: to \data, but will not change the current command prompt to D:.