Using cd command in Windows command line, can't navigate to D:\

235

82

This may be a stupid question, and I think I have looked elsewhere to find the answer... Might be a path issue, but when I open the command line and type from the C:\>:

cd D:\

I cannot get to the D drive. Even if I type:

cd D:\<folder name>

The command.exe will auto-complete the line with the tab key, so it knows where I'm at. It just doesn't print to screen the result or actually get me there. This problem exists for the network drives as well.

Now, if I use the chdir (cd) command like this:

chdir D: or cd d:

I get the print out of the D:\ below the command but it still says I'm in the C:\.

I feel like I'm missing something simple.

nicorellius

Posted 2010-04-27T15:35:09.807

Reputation: 5 865

5

See this answer "cd /d D:" http://superuser.com/a/135239/78897

– Pacerier – 2014-08-27T13:20:55.927

1Try this: cd /d d: – DevWL – 2018-03-24T21:10:30.397

I have been using pushd in place of cd pretty much everywhere as it behaves much better in situations like this. – Goyuix – 2012-01-19T16:02:51.590

Answers

334

Going back to the days of DOS, there's a separate "current directory" for each drive. cd D:\foldername changes D:'s current directory to the foldername specified, but does not change the fact that you're still working on the C: drive.

What you want is simple:

D:

Here you can see how the "separate current directory for each drive" thing works:

C:\Users\coneslayer>e:

E:\>c:

C:\Users\coneslayer>cd e:\software

C:\Users\coneslayer>e:

e:\Software>

coneslayer

Posted 2010-04-27T15:35:09.807

Reputation: 7 494

17In a "fastest gun in the west" situation, the winner is the one who puts the best explanation. +1, and I delete my similar answer. – Gnoupi – 2010-04-27T15:42:20.083

2Deleted mine, too. No need for the extra clutter. – th3dude – 2010-04-27T15:46:27.017

4-1 a)you haven't pointed out that the cd e:\software line did nothing. As if you stuck a phantom CD command in there Why? To make him think you were using CD when you weren't? and b)how on earth can you not mention /d enabling CDing to a particular directory on a different drive He did say using cd command so while it's good that you pointed out it how it can be done without the CD command d:<ENTER>, you should have mentioned for the CD command as well cd /d d: or cd /d d:\blah – barlop – 2016-07-27T22:28:43.273

3@barlop The cd E:\software does NOT do nothing. It changes the current directory of the E partition to the software folder, which is what is demonstrated when finally switching to the E partition with E:. Good suggestion with cd /d though. – miyalys – 2016-11-21T09:48:44.707

@miyalys interesting and great point – barlop – 2016-11-21T23:06:29.953

-1 for not mentioning the /d switch. Read this instead: https://superuser.com/a/135239/320611 – David Refoua – 2019-02-23T17:28:11.143

78

It did work, as the command is designed to work.

You simply don't know how it's actually supposed to work.

You're not using a Unix or Linux shell program. The cd command in Microsoft's command interpreter doesn't behave as the cd commands in such shells do. It behaves somewhat differently. In particular, it doesn't always change directory. In Unix and Linux shells, cd only ever sets the working directory. In Microsoft's command interpreter, cd sometimes queries it. There's no separate pwd command, so cd does two jobs.

If you give it no arguments, or an argument that is just a drive letter and a colon without a path, then it reports the current directory instead of changing it. If you give it no arguments, it reports the current directory of the current drive of the command interpreter process. If you give it only a drive letter and a colon as an argument, it reports the command interpreter process' current directory of that drive. Each drive has its own current directory in the command interpreter. (This is a fiction maintained by the run-time libraries for Microsoft's and several other vendors' implementations of various programming languages. Win32 itself doesn't work this way.)

So when you gave it d: as an argument, it reported the the command interpreter process' current directory on drive D to you, which happened to be D:\. If you'd given it no arguments at all, it would have reported C:\ to you.

If you want the cd command to always be in set mode and never be in query mode you need to add the /D option to it. This forces the command to always be in set mode, and also extends it so that it changes the current drive as well as changing a drive's current directory. (In other words, it works more like the underlying Win32 API actually does.)

So, for example, the command line

cd /d d:
will change directory to whatever the current directory on drive D is, and also change the current drive to drive D.

If you want to change the command interpreter process' current drive otherwise, the cd command is not the way. You do so by simply typing the drive letter and a colon:

d:

Further reading

  • JP Software (2011). CD/CHDIR TCC On-line Help.
  • Microsoft corporation (2001). Chdir (CD). TechNet Windows XP Command line reference A–Z.

JdeBP

Posted 2010-04-27T15:35:09.807

Reputation: 23 855

Since you're providing a hyperlink to JP Software's online help, you may also want to refer to JP Software's online help for their "CDD" command, as that is quite relevant to this conversation.

– TOOGAM – 2016-11-22T02:23:33.453

6Related post by Raymond Chen. – Daniel Beck – 2012-01-19T14:27:42.713

3Not completely right. If you do cd d:\ it changes the working directory on d:. If you do d:\ afterwards it will be at d:\. If you do cd d:\something\something nothing will happen at first. But if you do d:\ afterwards again, your path will be d:\something\something"! – sinni800 – 2012-01-19T15:06:37.300

4None of which contradicts what is written above in any way, sinni800 (apart from your getting the syntax for changing current drive wrong, that is, but I'll overlook that). I didn't include discussion of what happens when one supplies a pathname in an argument because (a) that's not what the question is about and (b) it's in the further reading. – JdeBP – 2012-01-19T15:24:56.880

6No, we're not. It would be wrong to talk of partitions instead of drives here, user unknown. For starters, partitions are not the same as volumes, and drive letters map to volumes, not partitions. And when one is talking at this level of abstraction, drive letter and current drive are the conventional terms, as used here, in the further reading indicated, and even in the cd /? help text. – JdeBP – 2012-01-19T17:09:27.113

2I have used this command for at least 20 years and never knew this. – Chris Ballance – 2013-03-07T16:23:27.537

55

Afraid this is incorrect. It's true from the days of DOS, but the command line in Windows NT and later is not DOS. In the command line that everyone uses today, you have the /D switch. The /d switch will change the current directory of the specified drive AND change to that directory. The /d switch must be specified before the path. For example:

C:\> cd /d D:\foo\bar\
D:\foo\bar\>

windows command prompt cd

Multiverse IT

Posted 2010-04-27T15:35:09.807

Reputation: 4 228

4+1 because I learned something new, but I don't think that anything I wrote is incorrect. – coneslayer – 2010-04-27T16:45:06.143

3Your answer is correct too, Multiverse IT, but coneslayer wasn't incorrect. Thanks for your efforts. I learned two great tricks on this question. – nicorellius – 2010-04-27T17:07:01.833

2From my perspective "What you want is simple ... D:" is incorrect. Yes it works and is a valid method of achieving the goal, but it is not, strictly speaking what he should want. Additionally, the way the comment is worded implies that you cannot use CD to do this - that implication is incorrect. – Multiverse IT – 2010-04-28T00:31:07.033

1his main issue is to "I cannot get to the D drive.". As such, the other answer is correct. Your solution takes simply one step less (which is good). It doesn't make the other one incorrect. – Gnoupi – 2010-04-28T08:05:11.387

typing just C: to change to the C: drive in Windows 10 worked – Yvonne Aburrow – 2017-01-11T11:22:24.390

1Hmm, "what he should want." Sounds rather presumptive ;-) – nicorellius – 2012-07-18T05:59:15.050

20

CD stands for Change Directory, and not Change Drive. So it would not change to D: like that. To achieve this you'd have to simply type in the drive letter

e.g.

d:

IUnknown

Posted 2010-04-27T15:35:09.807

Reputation: 2 018

16cd /D D: changes drives and directories... – Michael S. – 2012-01-19T13:34:30.863

But d: is a partition, not a drive. – user unknown – 2012-01-19T16:13:54.017

1@userunknown In the Dos 1.0 era when the shell was designed there were only floppy disks which AFAIK can't be partitioned. Initial hardrive support was only for the primary (first) partition on a drive. Extended partition support wasn't added until later. – Dan is Fiddling by Firelight – 2012-01-19T16:35:24.920

I don't see a MS-DOS 1.0 tag, nor 1.0 mentioned. Maybe you can't partition a drive with MS-DOS programs, but you can install an MS-DOS on a partitioned drive. I guess MS-DOS is out of support though, and the tag is there, because many users believe that cmd.exe and MS-DOS means the same, which is another error to address. Apropos: MS-DOS 1.0 was never published. – user unknown – 2012-01-19T17:07:16.400

1@userunknown The design decisions date back to the initial versions of DOS. Changing behavior would have broken older programs (see Daniel Beck's comment below). PS; according to Wikipedia MS DOS 1.x was published. – Dan is Fiddling by Firelight – 2012-01-19T18:50:01.053

9

The working directory in cmd.exe is maintained on a volume-by-volume basis; the Working Directory for the C: drive is different from the working directory for the D: drive.

When you pass only a drive letter to cd, it will print the working directory for the specified drive.

In your case, the working directory of the D: drive is the volume root itself, D:\.

To change volumes from C: to D: simply enter the drive letter:

C:\>D:
D:\>

Andrew Lambert

Posted 2010-04-27T15:35:09.807

Reputation: 7 136

2cd /D D: changes drives and directories... – Michael S. – 2012-01-19T13:34:41.847

1Partitions are mapped to a drive letter, and are virtually the same as a drive. You can also map a directory or share to a drive, and they behave the same. – Marty Fried – 2012-01-23T17:37:33.787

8

Use cd /D D: to do this. You can specify paths also.

Michael S.

Posted 2010-04-27T15:35:09.807

Reputation: 3 128

5

If you want to change drive in a DOS command prompt then you simply have to write:

[Drive Letter]:

For example, if you want to move to the D:\ drive then you just have to type the following in a command prompt:

D:

Darsak

Posted 2010-04-27T15:35:09.807

Reputation: 51

Oh wow, that makes things a hell of a lot easier. I always forget the /d so this makes switching much faster. – Mateen Ulhaq – 2017-03-23T02:54:30.813

You change the partition with [Drive Letter]:, believe me or test it out! – user unknown – 2012-01-20T06:39:40.857

2

pushd works even when you need to go to drive sub directory e.g. D:\Tests\Logs.

Just use it so:

pushd D:\Tests\Logs

If you want to go back to previous directory use popd:

C:\Users>pushd D:\Tests\Logs
D:\Tests\Logs>popd
C:\Users>

BladeMight

Posted 2010-04-27T15:35:09.807

Reputation: 360

0

While you going to search option in the tool bar and search for cmd or by selecting windows All app selecting command prompt then it takes to some other command prompt. Instead try pressing windows button + R and search for cmd it takes to C:> drive. From there you can navigate to D:> or anywhere you need

user609712

Posted 2010-04-27T15:35:09.807

Reputation: 11