The CD command returns the current directory, and the %CD% variable returns the same result in an environment variable:
c:\Temp\test\test1>cd c:\Temp\test\test1 c:\Temp\test\test1>@echo %cd% c:\Temp\test\test1
This command echoes the result of the CD command
for /F %f in ('cd') do @echo %f
so I should get
but actually I get:
c:\Temp\test\test1>for /F %f in ('cd') do @echo %f c:\work\Consulting
but using %CD% gives me this:
c:\Temp\test\test1>for /F %f in ('@echo %cd%') do @echo %f c:\Temp\test\test1
This was working on my machine when I last tested it a few months ago (it's in not often used script).
I've tested it on another machine and it works fine there. So I'm thinking that this is due to how I open the command prompt and set the working directory to
c:\work\Consulting using the following registry script:
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Microsoft\Command Processor] "Autorun"="cd /d C:\\Work\\Consulting"
(FYI this is needed if you want open an elevated command prompt to a particular directory)
Edit: Of course I have a workaround, but I was wondering what it is that I've done to cause this happen.