Is there a way to get the current working directory of a drive other than the current drive?
Windows stores the current directory of every drive and %cd% gets the current working directory of the actual drive.
If I change the drive in a batch script I can get the current working directory of the actual drive:
cd w:\Downloads
cd c:\Windows
c:
(echo %cd%)
w:
(echo %cd%)
Is there a way to get the current working directory without changing the actual drive?
After searching for an answer I found some hints on strange variables under https://blogs.msdn.microsoft.com/oldnewthing/20100506-00/?p=14133
use %=c:%) for the current directory of drive c or %=w:%) for w
Or in a batch script:
cd c:\Windows
cd w:\Downloads
(echo %=c:%)
(echo %=w:%)
UPDATE
As @RossRidge pointed out it is not Windows storing those strange variables but the DOS command processor. Those strange variables are only known in the current 'session'. The same holds for cd (see comment of @Stephan)
Opening two DOS command processors:
In the first DOS command processor:
cd c:\Windows
cd w:\Downloads
(echo %=c:%)
-> c:\Windows
(echo %=w:%)
-> w:\Downloads
cd w:
-> w:\Downloads
In the second DOS command processor:
(echo %=w:%)
-> %=w:% <- this variable is not set, not known
cd w:
-> w:\
Notice the inconsistent way to hold the 'current directory': cd returns the root directory after entering a DOS command processor. But %=w:% is not set until the directory changes!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With