Delphi 創建目錄及寫日誌文件

Delphi 創建目錄及寫日誌文件

var
  TF: TextFile;
  LogFile: string;
  txt :string;
  sysDir:string;

//創建按鈕
procedure TForm1.Button1Click(Sender: TObject);
begin
   sysDir:=extractfilepath(application.ExeName );
   if not directoryexists(sysdir+'log/') then
      createdir(sysdir+'log/');

   logfile:=sysdir+'log/'+formatdatetime('yyyymmdd',now)+'.txt';  

end;

//寫日誌按鈕
procedure TForm1.Button2Click(Sender: TObject);
begin

 //assignfile(logfile,'log.txt');
  AssignFile(tf,logfile);
 if fileexists(logfile) then
   append(tf)
 else
   rewrite(tf);

 writeln(tf,'123');
 closefile(tf);
end;

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章