How would you change the directory in a batch file then run the command in the new directory? I have got the batch file to change the directory, but will not run the command. It is not an exe, it is a file with -options. So basically I need to change the directory, then run a command that is saved in a string.
-
2post the batch file you have written.basiljames– basiljames2012-09-11 06:09:50 +00:00Commented Sep 11, 2012 at 6:09
-
What is the command you are unable to run after changing directory? Better post the batch file as said by basiljames.arulmr– arulmr2012-09-11 06:15:11 +00:00Commented Sep 11, 2012 at 6:15
Add a comment
|
3 Answers
Try using
pushd yourdir
filetorun -options
4 Comments
dannyn382
This is exactly what I needed. Worked perfectly. Thanks, Dan
Bali C
No worries, if this answered your question you should click on the tick to mark this as accepted.
Brian
Normally preferable to "cd", since one can use popd to restore the original directory.
Anusha
Why is pushd preferred over cd ?
I have given a sample code below to change the directory and run a command after that.
cd C:\ #Will change the directory to C:
ipconfig #Will return IP address details(any command can be used here)
pause #Will prevent command prompt from closing and waits for a keypress
Save this as a batch file filename.bat and you will get desired output. But make sure that the command entered is correct.
1 Comment
SeanC
also, if you need to change drive as well as directory, use
CD /D, as just CD will change the directory for that drive, but not change to that drive"cd" stands for "ChangeDirectory". With "cd" command you can change the directory.
See also: http://en.wikipedia.org/wiki/Cd_(command)
Cheers