简体   繁体   English

Windows cmd中CD / D切换的原因是什么?

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

At first I'd like to say that I do understand the purpose of the /D switch for the Windows Command Prompt cd command. 首先,我想说我确实理解 Windows命令提示符 cd命令的/D开关的用途。 I'm just curious why it works this way, and not other. 我只是好奇为什么它以这种方式工作,而不是其他方式。 As we all know, it does the following: 众所周知,它做了以下事情:

Use the /D switch to change current drive in addition to changing current directory for a drive. 除了更改驱动器的当前目录外,还可以使用/ D开关更改当前驱动器。

But every single time I enter (for example) cd F: , it's obvious enough that I would like to change the drive. 但每次我输入(例如) cd F: :,显然我想改变驱动器。 That is why I think this switch is redundant by itself. 这就是为什么我认为这种转换本身就是多余的。

So what's the point of explicitly setting this switch? 那么明确设置这个开关有什么意义呢? Why it isn't implied by default? 为什么默认不隐含?

Short answer: Because DOS behaved this way, and cmd tries to mimic DOS. 简答:因为DOS表现得这样,而cmd试图模仿DOS。

Originally, DOS had a 'current director' for each drive, so if you write cd d:\\folder you change the current directory for the D drive. 最初,DOS为每个驱动器都有一个“当前导向器”,所以如果你写cd d:\\folder你可以更改D驱动器的当前目录。

You can read more about this here: http://blogs.msdn.com/b/oldnewthing/archive/2010/10/11/10073890.aspx 你可以在这里阅读更多相关信息: http//blogs.msdn.com/b/oldnewthing/archive/2010/10/11/10073890.aspx

You have to remember, DOS dates back to before we even had mice to cut and paste text and when screens were 80x25 text. 你必须记住,DOS可以追溯到我们甚至还有鼠标切割和粘贴文本之前,屏幕是80x25文本。 Extra typing, particularly if you had to remember something and type it in later, was extremely painful. 额外的打字,特别是如果你必须记住一些东西并在以后输入它,是非常痛苦的。 Now imagine trying to work on more than one drive. 现在想象一下尝试在多个驱动器上工作。 With only one current directory, you'd have to fully specify directories on drives other than the current drive. 如果只有一个当前目录,则必须在当前驱动器以外的驱动器上完全指定目录。 That would require writing down the paths on the other drives because they wouldn't stay on screen. 这需要写下其他驱动器上的路径,因为它们不会停留在屏幕上。 Ouch. 哎哟。

So instead you could do: 所以你可以这样做:

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

Otherwise, it'd be: 否则,它将是:

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")

Now imagine it's more than one directory deep. 现在想象它不止一个目录。

And now, imagine if the program doesn't support subdirectories and you need to pass two paths to it on two different drives. 现在,假设程序不支持子目录,并且需要在两个不同的驱动器上传递两个路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM