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

19

6

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?

Diogo

Posted 2012-04-16T17:24:24.317

Reputation: 28 202

Question was closed 2012-04-16T19:29:38.980

2Related. – Daniel Beck – 2012-04-16T18:04:00.193

Answers

29

Try:

cd /d d:

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

jftuga

Posted 2012-04-16T17:24:24.317

Reputation: 2 877

1Looks like cmd.exe mimics the behavior of DOS pretty well in this situation, whereby the "current directory" for each drive is remembered distinctly. – LawrenceC – 2012-04-16T17:36:21.447

4This is the real answer to "why Widows works this way": because DOS did it that way. – KutuluMike – 2012-04-16T18:00:55.510

12

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.

KutuluMike

Posted 2012-04-16T17:24:24.317

Reputation: 450

6

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

uSlackr

Posted 2012-04-16T17:24:24.317

Reputation: 8 755