petervn
asked on
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
i'm afraid that someone will rename it
The path and filename of your program will be stored in the ParamStr(0) variable.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Whoops. Did I say variable? I meant function.
var FilePath,FileName:string;
...
FilePath:= ExtractFilePath(Applicatio n.ExeName) ;
FileName:= ExtractFileName(Applicatio n.ExeName) ;
...
FilePath:= ExtractFilePath(Applicatio
FileName:= ExtractFileName(Applicatio
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
Windows automatically adds the path + filename of a launched app as the first parameter (ParamStr() is zero-based).
Markus
var FilePath,FileName:string;
...
FilePath:= ExtractFilePath(Applicatio n.ExeName) ;
FileName:= ExtractFileName(Applicatio n.ExeName) ;
or
//only for app not usage tapplication
FilePath:= ExtractFilePath(ParamStr(0 ));
FileName:= ExtractFileName(ParamStr(0 ));
...
FilePath:= ExtractFilePath(Applicatio
FileName:= ExtractFileName(Applicatio
or
//only for app not usage tapplication
FilePath:= ExtractFilePath(ParamStr(0
FileName:= ExtractFileName(ParamStr(0
:-D
Now that is b*stardisation if ever I saw it...
Geoff M.
Geoff M.
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;