Programming Field

Changing the drive in the prompt - DOS/Command Prompt Reference

To change the current drive in MS-DOS prompt or Command Prompt, directly input ‘X:’ and press Enter, where ‘X’ is the drive letter followed by a colon.

X:

[Windows NT series/XP or later] Using the /D option with the Cd (Chdir) command allows you to change both the current drive and current directory simultaneously. Additionally, you can also change the drive with the Pushd command.

Details

When you want to move the current directory (present directory), you use the Cd (Chdir) command. However, for changing the drive, there is no specific command; you can directly input the drive letter followed by a colon and press Enter to move to that drive.

After moving to a different drive, the current directory is initially the root directory. However, if you have already changed it using commands like Cd, it will be set to that directory. The current directory of the current drive is retained even when you move to a different drive. So, if you move to another drive and then return, the current directory will be restored.

For information about the current drive (current directory) and the current directory, please refer to the page ‘Current directories in MS-DOS/Windows’.

Samples

Sample 1

D:
cd \MyDocs\Pictures

Changes the current directory to ‘D:\MyDocs\Pictures’.

Sample 2

cd D:\MyDocs\Pictures
D:

Similarly to Sample 1, change the current directory to ‘D:\MyDocs\Pictures’. Since the current directory exists for each drive, without using the /D option, you can use the Cd command to change the current directory of a different drive by prefixing it with a drive letter.

Sample 3

cd /D D:\MyDocs\Pictures

[Windows NT series/XP or later] Similar to Samples 1 and 2, change the current directory to ‘D:\MyDocs\Pictures’. If you want to change both the drive and directory together, use the Cd command with the /D option.

Sample 4

pushd D:\MyDocs\Pictures

[Windows NT series/XP or later] Similar to Samples 1, 2, and 3, change the current directory to ‘D:\MyDocs\Pictures’. The Pushd command also changes the current drive along with the directory. However, unlike the Cd command, you can use the Popd command to return to the drive and directory before the move.