tags:

views:

230

answers:

3

Hi,

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

+4  A: 
cd /d c:\temp\code
David Archer
+1 This works well coming from another drive too.
Wadih M.
+1  A: 

Sometimes, doing cd c:\temp\code only doesn't work if you're in another drive. This way works all the time:

c:
cd c:\temp\code
Wadih M.
+3  A: 

I'd suggest pushd over cd in this case. That way you can restore the previous directory with popd at the end. Unless a batch file should actually change the path even after it has been run, I'd always restore it at the end of the batch:

@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
Joey