如何从具有系统路径变量的路径获取绝对路径? [英] How to get absolute path from path with system path variables?

查看:118
本文介绍了如何从具有系统路径变量的路径获取绝对路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种简单的方法可以将具有系统路径变量的路径转换为绝对路径?

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

因此%ProgramFiles%\Internet Explorer\hmmapi.dll变为C:\Program Files\Internet Explorer\hmmapi.dll

我想知道是否存在可以执行此操作的API调用,还是我必须用困难的方式执行此操作并检测%..%序列并将其替换为相应的环境变量?

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?

推荐答案

您可以使用WinAPI函数ExpandEnvironmentStrings:

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;

这篇关于如何从具有系统路径变量的路径获取绝对路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆