How to get absolute path from path with system path variables?

冷暖自知 提交于 2019-12-10 03:16:56

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!