使用变量更改批处理文件中的目录
问题是:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
set
语句不会按照您期望的方式处理空格;您的变量实际上名为Pathname[space]
并且等于[space]C:\Program Files
。删除
=
符号两侧的空格,并将值放在双引号中:另外,如果您的命令提示符未向 C:\ 打开,则使用
cd
单独无法更改驱动器。使用
或
代替。
The
set
statement doesn't treat spaces the way you expect; your variable is really namedPathname[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:Also, if your command prompt is not open to C:\, then using
cd
alone can't change drives.Use
or
instead.
示例...使用
执行此操作的简单方法...以下是将 ISO 映像安装到特定驱动器的
simple way to do this... here are the example
this will mount the ISO image to the specific drive...use