how to change directory using Windows command line
Solution 1
The "cd" command changes the directory, but not what drive you are working with. So when you go "cd d:\temp", you are changing the D drive's directory to temp, but staying in the C drive.
Execute these two commands:
D:
cd temp
That will get you the results you want.
Solution 2
Another alternative is pushd
, which will automatically switch drives as needed. It also allows you to return to the previous directory via popd
:
C:\Temp>pushd D:\some\folder
D:\some\folder>popd
C:\Temp>_
Solution 3
cd
has a parameter /d
, which will change drive and path with one command:
cd /d d:\temp
( see cd /?
)
Solution 4
Just type your desired drive initial in the command line and press enter
Like if you want to go L:\\ drive,
Just type L: or l:
Related videos on Youtube
A. K.
llvm + clang contributor Compiler Engineer, Facebook, California Twitter: hiraditya
Updated on December 19, 2021Comments
-
A. K. over 2 years
I'm using
cmd.exe
(C:\WINDOWS\System32\cmd.exe) and I have to change my current directory to "D:\temp" i.e. temp folder in the D drive.When I try to
cd
nothing happens.C:\> cd D:\temp C:\>
I don't know what else to do here. Even pressing
tab
key does not give any hints. I have never got the reason to use cmd.exe until now when I have to. I mostly use Linux for development.If this helps: I'm on a remote login to another computer and
D:\temp
in on the remote machine, but so isC:\
where I have opened the terminal (cmd.exe).-
marlonpya almost 7 yearsonly add
D:
orC:
not required cd.. -
Zoe stands with Ukraine almost 7 yearsWhy is this closed as off-topic? CMD can be used in programming, for an instance related to ADB (Android debug bridge) and it can also be used to execute programs in other languages (e.g. C, Java, Python, etc). If the target is in a different drive, the command is used to open the appropriate drive. I would say it directly involves tools used in programming, as it can be used for so many different programming-related things includin, but not limited to, ADB, launching programs, etc
-
chris31389 almost 6 yearsThis applies to cmd command files :) - shouldn't be off topic
-
JohnAndrews over 5 yearsAgain a great example of a good question, but some programmers being way too strict or having something up their a*, which results in that a proper question gets closed as off topic or for some other reason. Happy to see the large number of upvotes.
-
A. K. over 2 yearsYeah, the first time it was closed shortly after being asked and I was kinda stuck for a bit because i was too new to Windows command line. I'm glad this question has already helped more than 800k people.
-
-
oleksa over 8 yearsthis does not work if cd command is executed for environment variable, for example
cd %temp%
. In case if current drive differs from temp folder drivecd %temp%
do nothing.cd /d %temp%
should be used as @Stephan said -
Shaiju T over 7 yearsi.e First change the Drive then change the Folder or directory, hope helps someone.
-
Andi AR over 7 yearsPerfect answer. No worries on source folder.
-
abdul qayyum about 6 yearsI ran second first and when I used Drive name it automatically went to directory so cd temp, D: also work
-
Mattwmaster58 about 6 yearsWay easier than going up and down folder levels!
-
Stephan over 3 yearsgives me
The filename, directory name, or volume label syntax is incorrect.
. Of course it does, because/drivename
is not a valid switch and therefore interpreted as a foldername, which doesn't exist. -
gouessej about 2 yearsIt's an excellent alternative to TCC/LE CDD: jpsoft.com/help/cdd.htm?q=cdd