In Windows command prompt, we can change the directory using the command cd . Both cd and chdir refer to the same command. Syntax of this command is explained below with some examples.
Change directory
When we launch command prompt, the default directory it opens with is C:\Documents and Settings\logind. This is in Windows XP. In Windows 7 command prompt opens up with the directory C:\Users\loginid. Now let’s say you want to traverse to the directory C:\Windows\System32. The command for this is given below.
C:\>cd C:\Windows\System32
(or)
chdir C:\Windows\System32
Change to a directory with spaces in the name
In Windows, we can have spaces in the directory names. cd command can interpret the space correctly. So we do not need to enclose quotes around the directory name, as with most of other windows commands. An example is shown below.
C:\>cd C:\Documents and Settings\cmdadmin C:\Documents and Settings\cmdadmin>
Change drive and directory with single command
The basic cd command does not work if you are trying to change to a directory that is located on a different drive. Say you are in C:\users\cmdadmin\ directory and want to change to E:\docs directory. If you run ‘cd e:\docs‘ you won’t get any error but you would still be in the same folder. Only when you switch the drive by running the command ‘E:’ you will move to the folder e:\docs. You can avoid this by using /d option with cd command.
Cd /D E:\docs
This command changes to the drive E: and also changes the directory to E:\docs.
Tips for changing directories in windows command prompt
If you frequently work with windows command line, then the below tips would help you in easily changing the directories in command line.
Use Pushd and Popd commands:
Pushd command is similar to cd but it also saves the current directory path. So if you want go back to the directory where you have come from, you can just use popd command. It will take you to the last directory you were working in.
C:\Program Files\Microsoft Office> pushd c:\WINDOWS\system32 C:\WINDOWS\system32> C:\WINDOWS\system32> popd C:\Program Files\Microsoft Office>
Pushd can remember all the previous directories you traversed as long as you change the directory using pushd instead of cd command. Using popd you can go back to all the previously visited folders in the reverse order. See the below example.
C:\WINDOWS\system32\drivers> pushd ..\ C:\WINDOWS\system32> pushd .. C:\WINDOWS> pushd .. C:\> pushd "c:\Program Files" C:\Program Files> popd C:\> popd C:\WINDOWS> popd C:\WINDOWS\system32>
Thanks very much indeed for this help.
None of these worked for me. Syntax of the command is incorrect.
pushd is also great for temporary mouting a UNC path to a drive letter.