Using cd
/chdir
you cannot change the current working directory (CWD) to one on a different drive unless first switching drives (2 steps) or including the /d
switch as part of your command (1 step).
cd /?
will display the command's help text.
From C:\Users\jessy
to E:\MyData
2 STEPS
1 | C:\Users\jessy> E:
2 | E:\> cd \MyData // also 'cd E:\MyData' & 'cd MyData'
| E:\MyData>
1 STEP
1 | C:\Users\jessy> cd /d E:\MyData
| E:\MyData>
Credit to Señor CMasMas for pointing out the shorter method.
��
Additional Reading
The way cd
deals with drives and directories reflects its roots in DOS. Windows really only has one current directory, however cmd.exe
uses environment variables tied to that particular session to set and maintain it's own current directory for each drive separate from Windows as well as any other cmd.exe
instances. If you'd like to read more, I have included a few links to get you started.
- A Current Directory for each drive?
//ss64.com/nt/cd.html - Why does each drive have its own current directory?
//devblogs.microsoft.com/oldnewthing/20101011-00/?p=12563 - How to get current working directory of another drive in Batch?
//stackoverflow.com/a/53078745
Other Approaches
pushd
[ credit: user @printf ]
- Will traverse drives without additional command switches
- Stores the current directory for later use by the
popd
command - See Learn > Windows Server > Windows Commands > Reference > pushd