10/06/2026

cd Not Changing Drives in cmd? Use cd /d

Short answer: in the Windows command prompt (cmd.exe), cd D:\projects changes the current folder on drive D but leaves you on the drive you were on. Use cd /d D:\projects to change the drive and the folder in one step, or type D: on its own line. PowerShell behaves differently: cd D:\projects switches drives there.

Which command to use

  • In cmd, a script or a prompt

    `cd /d D:\path`. One command, works from any drive.

  • In cmd, and you want to come back

    `pushd D:\path` then `popd`. Handy for a detour.

  • In PowerShell

    `cd D:\path` already changes the drive. `/d` is not needed there and is not a parameter.

  • Only to look

    `cd D:` prints the remembered folder for that drive and changes nothing.

What happens without /d

cmd remembers a current folder for every drive, and a separate current drive. Plain cd with a path on another drive updates the remembered folder for that drive and nothing else. Microsoft's reference describes the switch this way: /d "Changes the current drive as well as the current directory for a drive" (Microsoft Learn: cd, updated February 2026).

We ran this in a batch file on Windows 10 (version 22H2) with C: and D: drives:

cd /d C:\Windows
cd D:\
echo %CD%

The last line printed C:\Windows. The cd D:\ command had set drive D's remembered folder and the prompt stayed on C:. Typing D: then moved to D:\.

Four ways to change drive, and what each does

  • cd /d D:\projects switches drive and folder. It is the one to use in scripts.
  • D: switches to drive D, to whatever folder drive D last had.
  • pushd D:\projects also switches drive and folder, and popd returns you to where you were. In our test it printed the new folder and popd restored the previous drive and folder.
  • cd D: with no path does not change anything. It prints drive D's remembered folder, which the Microsoft page documents: used with only a drive letter, cd "displays the names of the current directory in the specified drive".

In a batch file

A script often needs to run from the folder it lives in, even when it is started from another drive. Use both pieces together:

cd /d "%~dp0"

%~dp0 expands to the drive and folder of the script, and /d makes the change work across drives. We tested this from a script in a temporary folder on C: after being on another folder; %CD% afterward matched the script's folder. Keep the quotes so a path with spaces survives.

FAQ

Why does cd not change drives in cmd?

Without /d, cd changes the remembered folder for the drive you name and keeps the current drive. Add /d, or type the drive letter on its own.

How do I change to another drive in the command prompt?

Type the drive letter and a colon, such as D:, or use cd /d D:\path to change the drive and the folder together.

What does cd /d do in a batch file?

It lets the script change both the drive and the folder. cd /d "%~dp0" moves to the folder the script is in, even if it was started from a different drive.

Filed under