如何使用批处理文件来改变当前的工作目录 [英] How to change current working directory using a batch file
本文介绍了如何使用批处理文件来改变当前的工作目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要编写一个批处理文件中一些帮助。
我有存储在变量根目录的路径如下:
I need some help in writing a batch file. I have a path stored in a variable root as follows:
set root=D:\Work\Root
然后我改变我的工作目录到这根如下:
Then I am changing my working directory to this root as follows:
cd %root%
当我从D盘上的任何位置执行此批处理文件这是成功完成。但是,当我从其他驱动器执行相同的批处理文件,CD%根%不起作用。
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%根%应正常工作。
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
来也更改驱动器。
CD /D %root%
这篇关于如何使用批处理文件来改变当前的工作目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文