How to change current working directory using a batch file

后端 未结 4 1499
心在旅途
心在旅途 2020-12-12 14:29

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

相关标签:
4条回答
  • 2020-12-12 15:14

    Try this

    chdir /d D:\Work\Root
    

    Enjoy rooting ;)

    0 讨论(0)
  • 2020-12-12 15:16

    Specify /D to change the drive also.

    CD /D %root%
    
    0 讨论(0)
  • 2020-12-12 15:26

    Just use cd /d %root% to switch driver letters and change directories.

    Alternatively, use pushd %root% to switch drive letters when changing directories as well as storing the previous directory on a stack so you can use popd to switch back.

    Note that pushd will also allow you to change directories to a network share. It will actually map a network drive for you, then unmap it when you execute the popd for that directory.

    0 讨论(0)
  • 2020-12-12 15:28

    A simpler syntax might be

    pushd %root%

    0 讨论(0)
提交回复
热议问题