任何理由分裂" CD"在Windows命令? [英] Any reason to split up "cd" commands in Windows?

查看:176
本文介绍了任何理由分裂" CD"在Windows命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我清理一些旧的Windows批处理文件在工作,并保持看到线路是这样的:

  D:
光盘\\
一些CD \\其他\\路径\\

没有任何理由(与command.com兼容性也许?)不只是写为

  CD / D D:\\一些\\其他\\路径\\


解决方案

CD 实际上并没有改变工作驱动器;它不仅改变了的该驱动器的工作目录的。这就是为什么它打破了这种方式。

一个例子可能有所帮助:

  C:\\用户\\大卫> CD D:\\一些\\路径
C:\\用户\\大卫>

请注意该驱动器并没有改变。

  C:\\用户\\大卫> D:
D:\\一些\\路径>

现在D:是工作盘,工作目录更改为你所指定的previously。

正如您所指出的, CD / D 将两者都做。 [更新:我一定是错过了 /天读你原来的职位:(当 - 对不起]

我相信你是正确的 - 有没有好的理由不使用单行 - 比COMMAND.COM(我敢pretty兼容性等肯定不支持 /天开关)。出于这个原因,我总是创造我的脚本文件使用的.cmd 扩展,如果他们依赖于COMMAND.COM不支持的功能。

有一个更好的选择恕我直言,是使用 PUSHD 这行为就像 CD / D - 也给你能够回去,无论你是之前(通过 POPD )。你甚至可以 PUSHD 来UNC路径( \\\\服务器\\共享)和Windows将创建一个临时驱动器号您。 (虽然我今天上午才发现功能,并且我运行的Win 7专业版,所以我不知道它是否可以在旧版本和/或家庭版)。

I'm cleaning up some old Windows batch files at work, and keep seeing lines like this:

D:
cd\
cd some\other\path\

is there any reason (compatibility with command.com maybe?) to not just write this as

cd /d d:\some\other\path\

解决方案

cd doesn't actually change the working drive; it only changes the working directory for that drive. That's why it's broken up that way.

An example might help:

C:\users\david>cd D:\some\path
C:\users\david>

Note the drive hasn't changed.

C:\users\david>D:
D:\some\path>

Now that D: is the "working disk", the working directory is changed to what you specified previously.

As you point out, cd /d will do both. [UPDATE: I must have missed the /d when reading your original post :( -- sorry]

I believe you're correct -- there's no "good" reason not to use the one-liner -- other than compatibility with COMMAND.COM (which I'm pretty sure doesn't support the /d switch). For this reason, I always create my script files with a .cmd extension if they depend on features not supported in COMMAND.COM.

A better alternative IMHO is to use pushd which behaves like cd /d -- and also gives you the ability to go back to wherever you were before (via popd). You can even pushd to a UNC path (\\server\share) and Windows will create a temporary drive letter for you. (Although I only found that feature this morning, and I'm running Win 7 Pro, so I'm not sure if it's available on older versions and/or Home editions.)

这篇关于任何理由分裂" CD"在Windows命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆