views:

170

answers:

1

Is there an easy way to translate a path with system path variables to an absolute path?

So %ProgramFiles%\Internet Explorer\hmmapi.dll becomes C:\Program Files\Internet Explorer\hmmapi.dll

I like to know if there is an API call that can do this, or do I have to do this the hard way and detect %..% sequences and replace them with the corresponding environment variable?

+9  A: 

You can use the WinAPI ExpandEnvironmentStrings function:

function ExpandEnvStr(const szInput: string): string;
  const
    MAXSIZE = 32768;
  begin
    SetLength(Result,MAXSIZE);
    SetLength(Result,ExpandEnvironmentStrings(pchar(szInput),
      @Result[1],length(Result)));
  end;
ThiefMaster
Yes, that was the function I was looking for. I just found it myself too, after finally using the right keywords at google.
The_Fox
ExpandEnvironmentStrings returns the length including the null character, so you have to substract 1 from the result to return the string without the null terminator.
The_Fox