How to change root path in .bat file?

In the .bat file, how can I change the root path to c: \ temp \ code

+3
source share
3 answers
cd /d c:\temp\code
+5
source

I would suggest pushdover cdin this case. This way you can restore the previous directory with popdat the end. If the batch file should not actually change the path even after running it, I always return it at the end of the package:

@echo off
rem change current directory
pushd C:\Temp\Code
rem ...
rem something your batch needs to do
rem ...
rem restore old working directory
popd
+4
source

Sometimes execution cd c:\temp\codejust doesn't work if you are on a different drive. This method works all the time:

c:
cd c:\temp\code
+1
source

Source: https://habr.com/ru/post/1711415/


All Articles