• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 501
  • Last Modified:

how to et current file name and path

how to know the path and file name of my project while it's running?
i'm afraid that someone will rename it
0
petervn
Asked:
petervn
  • 2
  • 2
  • 2
  • +2
1 Solution
 
cwpCommented:
The path and filename of your program will be stored in the ParamStr(0) variable.
0
 
gmayoCommented:
ShowMessage(Application.ExeName);

That includes the both the exe name and path information.

Geoff M.
0
 
cwpCommented:
Whoops. Did I say variable? I meant function.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
13_thCommented:
var FilePath,FileName:string;
...

FilePath:= ExtractFilePath(Application.ExeName);
FileName:= ExtractFileName(Application.ExeName);
0
 
DaFoxCommented:
Application.ExeName internally calls ParamStr(0), but it doesn't work with console apps (or wherever you don't have the TApplication object), so I'd rather follow Geoff's hint.
Windows automatically adds the path + filename of a launched app as the first parameter (ParamStr() is zero-based).

Markus
0
 
13_thCommented:
var FilePath,FileName:string;
...

FilePath:= ExtractFilePath(Application.ExeName);
FileName:= ExtractFileName(Application.ExeName);

or

//only for app not usage tapplication

FilePath:= ExtractFilePath(ParamStr(0));
FileName:= ExtractFileName(ParamStr(0));

0
 
DaFoxCommented:
:-D
0
 
gmayoCommented:
Now that is b*stardisation if ever I saw it...

Geoff M.
0
 
CyclovenomCommented:

Taken from Key Objects Library (KOL)

function GetStartDir : String;
var Buffer:array[0..260] of Char;
    I : Integer;
begin
  I := GetModuleFileName( 0, Buffer, Sizeof( Buffer ) );
  for I := I downto 0 do
    if Buffer[ I ] = '\' then
    begin
      Buffer[ I + 1 ] := #0;
      break;
    end;
  Result := Buffer;
end;
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 2
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now