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.)