24 Votes

Delphi/Lazarus: Get Program Folder / Path of own Application

Question by Compi | Last update on 2021-07-01 | Created on 2016-06-04

I would like to determine the folder in which my program file respectively the EXE file of my application is stored. In other words, the directory from which the program has been started and in which accordingly the EXE is located.

Is there any function available for that?

ReplyPositiveNegative
2Best Answer2 Votes

That is quite easy. In Paramstr(0) as well as in Application.ExeName, the full path to your application file is stored.

In order to get the corresponding folder, you only have to extract the path from Paramstr(0) or Application.ExeName.

var
  AppFolder: string;
begin
  AppFolder := ExtractFilePath(Application.ExeName);

  // or

  AppFilder := ExtractFilePath(Paramstr(0));
end;

As you can see, you can achieve this with using the function ExtractFilePath(). In this case, this function is cutting off the program file from the path and is correspondingly providing the desired path to your EXE.
Last update on 2021-07-01 | Created on 2016-06-04

ReplyPositive Negative
Reply

Related Topics

Rename File to its Folder Name

Tutorial | 0 Comments

Delphi: System-Wide HotKey

Tutorial | 1 Comment

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.

Participate

Ask your own question or write your own article on askingbox.com. That’s how it’s done.