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.
To change to a specific drive letter while the command prompt directory is using a different drive letter than the one you need to change to, simply use the /D parameter with the CD command (e.g. CD /D <DriveLetter>: ) to change to a different drive letter before running proceeding commands.
Try using
pushd yourdir
filetorun -options
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.
"cd"
stands for "ChangeDirectory"
. With "cd"
command you can change the directory.
See also: http://en.wikipedia.org/wiki/Cd_(command)
Cheers
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With