Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 986
The_Fox Avatar asked May 14 '10 09:05

The_Fox


People also ask

How do I find the absolute path of a file?

You can determine the absolute path of any file in Windows by right-clicking a file and then clicking Properties. In the file properties first look at the "Location:" which is the path to the file.

How do I get system variable in path?

Select Start select Control Panel. double click System and select the Advanced tab. Click Environment Variables. In the section System Variables find the PATH environment variable and select it.

How do I find my PATH variable in CMD?

To list ALL the environment variables and their values, start a CMD and issue the command " set ", as follows, // Display all the variables (in NAME=VALUE pairs) set COMPUTERNAME=xxxxxxx OS=xxxxxxx PATH=xxxxxxx ....... Try issuing a " set " command on your system, and study the environment variables listed.

How do you add multiple paths to environment variables?

In the Environment Variables window (as shown below), highlight the Path variable in the System Variable section and click the Edit button. Add or modify the path lines with the paths you want the computer to access. Each different directory is separated with a semicolon, as shown below.


1 Answers

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;
like image 131
ThiefMaster Avatar answered Oct 25 '22 00:10

ThiefMaster