问题
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?
回答1:
You can use the WinAPI function ExpandEnvironmentStrings
:
function ExpandEnvStr(const szInput: string): string;
const
MAXSIZE = 32768;
begin
SetLength(Result,MAXSIZE);
SetLength(Result,ExpandEnvironmentStrings(pchar(szInput),
@Result[1],length(Result)) - 1);
end;
来源:https://stackoverflow.com/questions/2833021/how-to-get-absolute-path-from-path-with-system-path-variables