如何使用批处理文件更改当前工作目录 [英] How to change current working directory using a batch file

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

问题描述

我需要一些帮助来编写批处理文件.我有一个存储在变量根中的路径,如下所示:

I need some help in writing a batch file. I have a path stored in a variable root as follows:

set root=D:WorkRoot

然后我将我的工作目录更改为此根目录,如下所示:

Then I am changing my working directory to this root as follows:

cd %root%

当我从 D 驱动器上的任何位置执行此批处理文件时,这已成功完成.但是当我从其他驱动器执行相同的批处理文件时, cd %root% 不起作用.

When I execute this batch file from anywhere on the D drive this is done successfully. But when I execute the same batch file from some other drive, cd %root% doesn't work.

有没有办法从根变量中获取驱动器号?然后我可以先将当前目录更改为该驱动器,然后 cd %root% 就可以工作了.

Is there a way I can get the drive letter from the root variable? I can then change the current directory to this drive first and then cd %root% shall work.

推荐答案

指定 /D 也可以更改驱动器.

Specify /D to change the drive also.

CD /D %root%

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

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