How to change directory to run .bat files from different drive?
WindowsBatch FileWindows Problem Overview
I have some .bat files that I run from the local directory (e.g. C:\Users\pozna001). However, when I try and change the directory to a data drive using cd F:\nrcs_project
to run the .bat files from a different location, I see that the command prompt does not recognize the cd
command. How can I change the directory in the command prompt so that I can run these .bat files from a different drive (i.e. a data drive connected to a server)?
Windows Solutions
Solution 1 - Windows
CD /D F:\nrcs_project
Use the /D
switch to change current drive in addition to changing current directory for a drive.
Solution 2 - Windows
If you need to go from a device to another (in your case from C:\
to F:\
, you need to type F:
before/after you entered your cd
command, so it will go on the F
device. Otherwise, you can use the /D
parameter of the cd
function.
So to sum up,
$C:\Folder> F:
$F:\>cd F:\whatever
$F:\whatever>...
or
$C:\Folder> cd F:\whatever
$C:\Folder> F:
$F:\whatever>...
or
$C:\Folder> cd /D F:\whatever
$F:\whatever>...
Solution 3 - Windows
You first need to type F: to change to the F:\ drive, then you can use the CD command
Or you can use the /D switch to do it all in one shot:
CD /D F:\nrcs_project
Solution 4 - Windows
the command will look like following:
F: && cd nrcs_project
Solution 5 - Windows
Both solution above are correct.
The fastest is:
cd /d f:\nrcs_project
But you could change drive first, then the directory.
Use cd /? and it will show you all params.
Solution 6 - Windows
pushd "F:\nrcs_project"
this will allow also to return to the previous direcotry with popd
Mind that it is a good practice to enclose paths with double quotes in case of special characters,spaces and so on..