使用变量在批处理文件中更改目录 [英] change directory in batch file using variable

查看:94
本文介绍了使用变量在批处理文件中更改目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是问题:

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?

推荐答案

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

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"

此外,如果您的命令提示符未对C:\打开,则仅使用cd不能更改驱动器.

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

使用

cd /d %Pathname%

pushd %Pathname%

相反.

这篇关于使用变量在批处理文件中更改目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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