1、Delphi 打开目录和txt文件模块

//1、打开目录和打开txt文件
procedure TMainForm.bbtnOpenLoClick(Sender: TObject);
var
sLogName: string;
begin
sLogName := Pub_EXEPath + '\日志\' + FormatDateTime('yyyy-mm-dd',date())+'.txt';
if not FileExists(sLogName) then
begin
MessageBox(0, '今日无错误日志!', '提示', MB_OK + MB_ICONINFORMATION);
Exit;
end;
try
OpenLog(sLogName);
except on E : Exception do
begin
LogInfo('打开日志文件出错,原因:' + E.Message, True);
MessageBox(0, '打开日志文件出错,请重试!', '错误', MB_OK + MB_ICONERROR);
end;
end;
end; procedure TMainForm.bbtnOpenLogFolderClick(Sender: TObject);
var
sDirName: string;
begin
sDirName := Pub_EXEPath + '\日志';
if not DirectoryExists(sDirName) then CreateDir(sDirName);
try
OpenLogDirectory(sDirName);
except on E : Exception do
begin
LogInfo('打开日志目录出错,原因:' + E.Message, True);
MessageBox(0, '打开日志目录出错,请重试!', '错误', MB_OK + MB_ICONERROR);
end;
end;
end; -------
procedure TMainForm.OpenLogDirectory(DirName: string);
begin
ShellExecute(Handle,'Open',PChar(DirName), nil, nil, 1);
end; procedure TMainForm.OpenLog(FileName: string);
begin
ShellExecute(Handle, 'Open', PChar('NotePad'), PChar(FileName), nil, SW_SHOW);
end;

  

上一篇:How to install 64-bit Google Chrome 28+ on 64-bit RHEL/CentOS 6 or 7


下一篇:闲来无聊,研究一下Web服务器 的源程序