I created a new environment variable via Windows 7 advanced system settings:

VAR_MYPATH = "D:\someFolder"

I added the new variable to the path in the same dialog:


When I run a new command prompt and type "CD %VAR_PATH%", no error is returned, but the command prompt does not change to "D:\someFolder".

If I attempt to launch a batch file under that folder from my C drive I end up with an error:

c:> %VAR_MYPATH%\someSubfolder\theBatchFile.bat
The system cannot find the path specified

All the paths are correct, so what am I missing to get the environment variable to work?

  1. For compatibility reasons with MS-DOS and COMMAND.COM, the Windows cmd.exe shell maintains a list of "current directories", one for each drive letter, and the cd command changes the directory, but not the current drive.

    Use cd /d %var_mypath% to also change the current drive.

  2. Do not put quotation marks in the variable value. If you do, then %VAR_MYPATH%\someSubfolder\theBatchFile.bat will expand to "d:\someFolder"\someSubfolder\theBatchFile.bat, which may confuse things. (Again, for compatibility, cmd.exe inherits many quirks from COMMAND.COM, including a strange quoted text parser.)

  3. Make sure the variable actually exists in your current cmd.exe window, either by running set var_mypath or echo %var_mypath%. (Each process inherits environment from its parent.)

  • Thank-you for the prompt response. I confirmed that the variable exists and there are no quotations. Your suggestion for #2 worked. I still cannot launch the batch file from the C drive though. Any ideas. – TERACytE May 22 '11 at 20:21
  • @TERACytE: Is the batch file in C: or D:? – grawity May 22 '11 at 20:23
  • On D: (d:\someFolder\someSubfolder\theBatchFile.bat). I want to run it from anywhere though (e.g. c:). – TERACytE May 22 '11 at 23:16
  • @TERACytE: Do echo %VAR_MYPATH% \someSubfolder \theBatchFile.bat and dir %VAR_MYPATH% \someSubfolder \theBatchFile.bat show the correct file? Does the path have spaces in it? Are you sure the error isn't actually displayed by the batch file itself? Try commenting out any echo off statements to see. – grawity May 22 '11 at 23:32
  • I got it! There was a space just before the last slash in the path. Thank-you for your help. – TERACytE May 23 '11 at 0:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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