DELPHI获取程序自身路径的函数
DELPHI获取程序自身路径的函数:
(1)
ExtractFilePath(FileName:String) //该函数返回路径名,其结尾字符总是“\”
ExtractFileDir(FileName:String) //该函数同样返回路径名,但不包括结尾的字符“\”,除非返回的路径是根目录。
Application.ExeName //返回自身应用程序名称
ExtractFileName(Application.ExeName)//返回自身应用程序名称
具体实现:
ExtractFileDir(Application.Exename);
ExtractFilePath(Application.Exename);
ExtractFilePath(ParamStr(0));
(2)
GetCurrentDir
function GetCurrentDir: string;
description:
The GetCurrentDir function returns a fully qualified path name for the current working drive and directory.
实例:
var sCurD : string;
sCurD := GetCurrentDir;
ShowMessage('Current folder: ' + sCurD);
明天需要调试的代码:
procedure TForm1.Button1Click(Sender: TObject);
begin
ShowMessage(ExtractFileDir(Application.Exename)); // 如: c:\temp
ShowMessage(ExtractFilePath(Application.Exename)); // 如: c:\temp\
ShowMessage(GetCurrentDir) or ShowMessage(GetCurrentDir());
end;