1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Bug in variable expansion

Discussion in 'Support' started by thorsten, Jun 3, 2011.

  1. thorsten

    Joined:
    Aug 16, 2008
    Messages:
    124
    Likes Received:
    0
    [Lates TCC (v67)]

    [Cmd.exe]
    > dir "%ProgramFiles(x86)%"
    [...]
    Directory of C:\Program Files (x86)

    31-May-11 00:12 <DIR> .
    [...]
    1 File(s) 174 bytes
    26 Dir(s) 112,201,871,360 bytes free

    [TCC]
    dir "%ProgramFiles(x86)"
    TCC: (Sys) The system cannot find the file specified.
    "C:\Program Files(x86)"
    0 bytes in 0 files and 0 dirs
    112,201,871,360 bytes free

    Note that TCC has expanded %ProgramFiles(x86) to "C:\Program Files(x86)" (instead of "C:\Program Files (x86)" (with space between Files and (x86)".

    But:
    > set ProgramFiles(x86)
    C:\Program Files (x86) (which is correct)
     
  2. Steve Fabian

    Joined:
    May 20, 2008
    Messages:
    3,520
    Likes Received:
    4
    Look at the variable function @SHFOLDER.

    dir "%@shfolder[42]" will do the job!
    --
    HTH, Steve
     
  3. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    9,860
    Likes Received:
    83
    Not a bug. The ( and ) are not valid variable name characters, so the parser is expanding "%ProgramFiles" and then appending "(x86)" to the result.

    If you want to use unusual characters in the filename, you can force the parser to recognize them with the [] syntax:

    echo %[ProgramFiles(x86)]

    Or you can use the CMDVariables=Yes option in your TCMD.INI, which will force all variable expansion to use the CMD syntax (which requires a leading and trailing %).
    <DIR>
    </DIR>
     
  4. thorsten

    Joined:
    Aug 16, 2008
    Messages:
    124
    Likes Received:
    0
    So Microsoft is not following its own rules by including characters which are not valid as variable names? Or does it just not follow TCC's rules?

    Anyway, the %[] is very good advice.

    Thanks, Thorsten
     
  5. Steve Pitts

    Joined:
    Jul 7, 2008
    Messages:
    159
    Likes Received:
    0
    Who knows, since I don't suppose it is documented anywhere and even Windows XP lets me create variables with brackets in the name. Under CMD it will never be an issue (because you have to close the variable name with a second percent sign) but 4DOS et al have always worked differently. The thing that really bugs me is why include the brackets at all, since ProgramFilesx86 would be just as sensible a name.
     

Share This Page