Windows cmd中的CD /D开关是什么原因?

What is the reason for the CD /D switch in Windows cmd?

起初我想说我理解 /D 开关用于 Windows 命令的目的提示cd命令。我只是好奇为什么它会以这种方式工作,而不是其他方式。众所周知,它执行以下操作:

Use the /D switch to change current drive in addition to changing current directory for a drive.

但每次我输入(例如)cd F:,很明显我想更换驱动器。这就是为什么我认为这个开关本身是多余的。

那么明确设置这个开关有什么意义呢? 为什么默认情况下不暗示它?

简短回答:因为 DOS 的行为方式是这样的,并且 cmd 试图模仿 DOS。

最初,DOS 对每个驱动器都有一个 'current director',所以如果你写 cd d:\folder,你就改变了 D 驱动器的当前目录。

您可以在此处阅读更多相关信息: http://blogs.msdn.com/b/oldnewthing/archive/2010/10/11/10073890.aspx

您必须记住,DOS 可以追溯到我们甚至没有鼠标来剪切和粘贴文本以及屏幕是 80x25 文本之前。额外的打字,特别是如果你必须记住一些东西,然后再输入,是非常痛苦的。现在想象一下尝试在多个驱动器上工作。只有一个当前目录,您必须在当前驱动器以外的驱动器上完全指定目录。这将需要记下其他驱动器上的路径,因为它们不会留在屏幕上。哎哟

所以你可以这样做:

dir a:           <- See what dir I need
cd a:foo         <- This one
dir a:           <- See what file
dir b:           <- See what dir I need
cd b:bar         <- This one
dir b:           <- See what file
a:program b:data <- use them both

否则为:

dir a:                <- See what dir I need
cd a:foo              <- This one
dir a:                <- See what file (lots of scroll)
dir b:\               <- See what dir I need (scroll)
cd b:\bar             <- This one
dir b:                <- See what file (lots of scroll)
a:\foo\program b:data <- use them both (had to remember "foo")

现在假设它不止一个目录那么深。

现在,想象一下,如果程序不支持子目录,而您需要在两个不同的驱动器上将两条路径传递给它。