3

I am trying to change directory from the C drive to the E drive, but it’s not happening, as shown below:

C:\>cd E:\Program files\wkhtmltopdf

C:\>echo %cd%
C:\

It says C:\ is the current directory even after changing directory.  Please correct my mistake.

1
  • User Powershell instead? It doesn't have this old behavior.
    – Zoredache
    Commented Jul 1, 2014 at 20:57

3 Answers 3

6

This is normal behavior. CD stands for Change Directory. In order to change the drive, go to it by typing: E: followed by enter

C:\>E:_

E:\Program Files\wkhtmltopdf>_

It will remember your cd action though, so the new path should be what you've cd'd to.

5
  • No, its not working ! i tried the same thing and did echo it says C drive only > C:\>cd E: E:\Program files\wkhtmltopdf C:\>echo %cd% C:\
    – logan
    Commented Jul 1, 2014 at 17:25
  • 4
    Don't type CD....Just type E: then hit enter.
    – EBGreen
    Commented Jul 1, 2014 at 17:26
  • done ! working :)
    – logan
    Commented Jul 1, 2014 at 17:28
  • @logan indeed. Don't type cd e:. Only E:. See my example code of what it'd look like in your commandprompt window.
    – LPChip
    Commented Jul 1, 2014 at 17:28
  • @logan good to hear. Feel free to mark my answer as answered. :)
    – LPChip
    Commented Jul 1, 2014 at 17:29
2

Change the current drive

By default, the cd or chdir commands won't change the drive letter you're currently on; you need to use the /d parameter. For example:

cd /d E:

You can also use a specific path, if you want:

cd /d "E:\Program files\wkhtmltopdf"

As an alternative you can use the pushd (push directory) command, like this:

pushd "E:\Program files\wkhtmltopdf"

The main advantage over the cd command is that you can use popd to easily restore the previous working directory and drive. In addition, the pushd command also provides support to UNC paths.

Further reading

3
  • It’s been my experience that you don’t need to quote the arguments to cd and pushd commands, even if they contain spaces. Commented Jul 1, 2014 at 21:38
  • 1
    @Scott When command extensions are enabled (and by default they are), space characters are not treated as delimiters when using e.g. the pushd command. Otherwise quotes are required. You can confirm that by running this command in a command prompt: start cmd /e:off /k pushd %programfiles% Usually %programfiles% expands to C:\Program Files, and you'll get the following error: The system cannot find the path specified. The fix? Quotes. I prefer to use them either way, so I'm confident enough the command will work regardless of extensions, spaces, or planetary alignment.
    – and31415
    Commented Jul 2, 2014 at 8:07
  • Thanks; good to know. I am in favor of using quotes whenever they might possibly be needed, and now I know that they “might possibly be needed” for cd and pushd. Commented Jul 2, 2014 at 21:30
0

The part of the answer that nobody else has explained is that Windows keeps track of (up to) 26 different current directories for each process (one for each drive), so, when you type

C:\> cd E:\Program Files\wkhtmltopdf

you are changing your E: working directory to \Program Files\wkhtmltopdf -- but (as the other answers have explained), you’re not changing your current drive to E:, so you don’t see the change in working directory.  (%CD% shows only the current directory on the current drive; it doesn’t show the other 25 current directories.)  So, you could type

C:\> cd E:\Program Files\wkhtmltopdf

and then

C:\> E:

and you would find yourself in E:\Program Files\wkhtmltopdf.  But that’s messy and confusing; use one of the techniques in the other answers.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .