Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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:

PATH = ...;%VAR_MYPATH%

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?

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted
  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.)

share|improve this answer
    
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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