使用变量更改批处理文件中的目录

发布于 2024-10-01 20:44:50 字数 132 浏览 0 评论 0原文

问题是:

set Pathname = C:\Program Files
cd %Pathname%
pause

正如我所期望的那样,上面的内容不会更改目录。有人可以告诉我为什么吗?

Here's the question:

set Pathname = C:\Program Files
cd %Pathname%
pause

The above doesn't change the directory, as I would expect. Can anybody please tell me why?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

ぃ双果 2024-10-08 20:44:50

set 语句不会按照您期望的方式处理空格;您的变量实际上名为 Pathname[space] 并且等于 [space]C:\Program Files

删除 = 符号两侧的空格,并将值放在双引号中:

set Pathname="C:\Program Files"

另外,如果您的命令提示符未向 C:\ 打开,则使用 cd单独无法更改驱动器。

使用

cd /d %Pathname%

pushd %Pathname%

代替。

The set statement doesn't treat spaces the way you expect; your variable is really named Pathname[space] and is equal to [space]C:\Program Files.

Remove the spaces from both sides of the = sign, and put the value in double quotes:

set Pathname="C:\Program Files"

Also, if your command prompt is not open to C:\, then using cd alone can't change drives.

Use

cd /d %Pathname%

or

pushd %Pathname%

instead.

余罪 2024-10-08 20:44:50

示例...使用

cd program files
cd poweriso
piso mount D:\<Filename.iso> <Virtual Drive>
Pause

执行此操作的简单方法...以下是将 ISO 映像安装到特定驱动器的

simple way to do this... here are the example

cd program files
cd poweriso
piso mount D:\<Filename.iso> <Virtual Drive>
Pause

this will mount the ISO image to the specific drive...use

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文