Solved

how to et current file name and path

Posted on 2003-11-15
9
496 Views
Last Modified: 2010-05-18
how to know the path and file name of my project while it's running?
i'm afraid that someone will rename it
0
Comment
Question by:petervn
  • 2
  • 2
  • 2
  • +2
9 Comments
 
LVL 3

Expert Comment

by:cwp
ID: 9754152
The path and filename of your program will be stored in the ParamStr(0) variable.
0
 
LVL 8

Accepted Solution

by:
gmayo earned 50 total points
ID: 9754250
ShowMessage(Application.ExeName);

That includes the both the exe name and path information.

Geoff M.
0
 
LVL 3

Expert Comment

by:cwp
ID: 9754281
Whoops. Did I say variable? I meant function.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Expert Comment

by:13_th
ID: 9754443
var FilePath,FileName:string;
...

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

Expert Comment

by:DaFox
ID: 9754568
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
 

Expert Comment

by:13_th
ID: 9754722
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
 
LVL 6

Expert Comment

by:DaFox
ID: 9754792
:-D
0
 
LVL 8

Expert Comment

by:gmayo
ID: 9754884
Now that is b*stardisation if ever I saw it...

Geoff M.
0
 

Expert Comment

by:Cyclovenom
ID: 9760388

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question