Re: Whats the %=C:% environment variable used for ?
Maria Sophia <[email protected]> Fri, 6 Feb 2026 11:35:52 -0500
| Newsgroups | alt.comp.os.windows-xp,alt.windows7.general,alt.comp.os.windows-10 |
|---|---|
| Organization | BWH Usenet Archive (https://usenet.blueworldhosting.com) |
| Message-ID | <[email protected]> |
Frank Slootweg wrote: > R.Wieser <[email protected]> wrote: >> Hello all, >> >> A couple of days ago I was looking at the envronment variables, and noticed >> a variable named "=C:", containing the current path of that drive. > > Current working directory, to be precise. > >> Can anyone tell me what it was/is used for ? > > Google, which you apparently don't want to use, says (amongst others): > > "The %=C:% environment variable in Windows is a hidden, special > system-wide variable that stores the current working directory for the > C: drive. > > It is part of a legacy mechanism (dating back to MS-DOS) that allows > the command processor (cmd.exe) to track separate current directories > for every drive letter, rather than having one single global current > directory for the whole system. > > Here are the key details about %=C:%: > > * Function: It keeps track of where you are in the C: drive if you are > currently working on a different drive (e.g., if you are in D:\Data > but type cd C:\Users, %=C:% will be updated to C:\Users). > > * Automatic Management: This variable is managed automatically by > cmd.exe when you use the cd (chdir) command." > >> Remarks: Using the command-prompt it doesn't appear in the "set" list, and >> it can be read, but not written. > > Google confirm that behaviour. > > It also gives a comparison with other variables. such ad %CD% > %SystemDrive% and mentions the somwhat obvious: > > "If you change drives, other variables like %=D:%, %=E:%, etc., are > created for those respective drives.". Windows contains secrets normally kept hidden under the floorboards. Following on what Frank said, it turns out Windows creates "drive-specific current directory" environment variables which look funnily like this. =C: =D: =Z: Each one stores the current working directory (cwd) for that drive. Try this: C:\> cd \Windows C:\Windows> D: D:\> cd \Games D:\Games> C: C:\Windows> Notice how switching back to C: returns you to C:\Windows automatically? That's because Windows stored it in that =X: stuff. They're maintained internally by the OS, not by the shell so you can't read them (echo %=C:%) or see them with set or even write to them. Try these proof-of-concept examples: C:\> cd \Windows C:\Windows> echo %=C:% C:\Windows Switch drives: C:\Windows> D: D:\> echo %=C:% C:\Windows It stays the same until you change directories on C:. It's mysterious. Much like the %CD% vs. %__CD__% split %__CD__% === an internal variable used by cmd.exe to track the raw current directory path including UNC paths (\\server\share), extended path lengths (\\?\C:\very\long\path), temp dirs, exact casing, setc. It's the true working directory as the command interpreter sees it. You might not notice the difference unless you're in a UNC or long path: C:\> echo %__CD__% Just like the =C: variables, it's protected. Don't even get me started on the bizarre CONIN$/CONOUT$ handles! -- Windows contains secrets normally kept hidden under the floorboards.