2

This question already has an answer here:

I have a surface pro 3 with a 32gb SD card. I've set the OneDrive location to this SD card (since they removed the placeholder feature and so I am forced to download everything). The drive letter assigned to the SD card is D:\, verified by disk management utility.

The problem is that I am unable to acces this drive/card with command line - both regular and admin elevated. ie, the command cd D:\ simply just returns nothing and stays in the current folder.

This is causing quite a few command line tools to break on my computer as it dosnt return an error (but nothing seems to work).

The answer marked below is correct. However, for more information try CMD cd to other drives except C:\ not working

marked as duplicate by DavidPostill, Community May 13 '16 at 21:24

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

3

Unlink Linux, windows is odd.


Just type this command

D:

or

D:\

This will switch to the drive


  • That works, but why dosnt cd work? Some of my extensions/tools create a path dynamically which have cd built into them. I don't want to end modifying extensions, that's a bit tedious – masfenix May 13 '16 at 0:56
  • I've updated my question to a duplicate I found. Should've searched first. – masfenix May 13 '16 at 0:58
  • Its just a weird way windows decides to do it.... I dunno :| – f3rn0s May 13 '16 at 1:17
  • @masfenix: As for why it doesn't work and what's the reasoning behind all this, see my answer below – CherryDT May 13 '16 at 8:23
5

Windows has the concept of per-drive current paths, at least in the shell. This is from the old days where you might have been working with two floppy disks and have different folders open in them and you were switching between them. And actually, subfolders were only introduced in DOS 2.0, I believe, and before that there were only different drives and no backslashes and no cd.

Therefore, switching drives is done like this:

C:\> D:

D:\>

...while changing one of the current directories is done using cd like this:

D:\> cd relative_folder

D:\relative_folder> cd D:\absolute_folder

D:\absolute_folder>

It is possible to change the directory on another drive without switching to that drive, and this is what you were accidentally doing:

D:\absolute_folder> cd C:\test

D:\absolute_folder> C:

C:\test> D:

D:\absolute_folder>

It is also possible to refer to the current path of another drive by just specifying the drive letter without backslash:

D:\absolute_folder> dir C:
Directory listing of C:\test
...

D:\absolute_folder> dir C:hello
Directory listing of C:\test\hello
...

D:\absolute_folder> dir C:\
Directory listing of C:\
...

D:\absolute_folder>

And the solution to your problem: In modern Windows, the cd command has a switch /d to implicitly switch drives as well:

D:\absolute_folder> cd /d C:\something

C:\something>

Side note: the current paths for the individual drive (for the current process - current paths are per process!) are stored as magic hidden environment variables called =C:, =D: etc.

You can't assign them normally due to the equal sign, but you can view them using echo %=C:% and such or by listing all environment variables including hidden ones using a hack (note the doublequote):

C:\something> set "
=C:=C:\something
=D:=D:\absolute_folder
...

You can also see the current path of another drive using cd with a drive letter without any path:

C:\something> cd D:
D:\absolute_folder

C:\something>

For more information, check this out: https://blogs.msdn.microsoft.com/oldnewthing/20100506-00/?p=14133

(Note that outside of the shell, programs don't have to care about this, because there is just one current working directory the Windows system will actually use, not one per drive. The "per-drive" stuff is only a thing built on top by the shell, because it worked like this since DOS.)

  • Thank you. I was able to modify my tools and extensions (that run off C and call cd to include the /d flag. – masfenix May 13 '16 at 21:26

Not the answer you're looking for? Browse other questions tagged or ask your own question.