Procedure SaveLog(LogStr:String);//记录日志文件
var
DirectoryPath,logFileName:String;
begin
DirectoryPath := ExtractFilePath(paramstr(0)) + 'log\\';
logFileName := FormatDateTime('YYYYMMDDhh',now)+'.txt';//每小时记录一个文件
if (not DirectoryExists(DirectoryPath)) then
begin
CreateDirectory(pchar(DirectoryPath),nil);
end;
if not fileExists(DirectoryPath + logFileName ) then
begin
NewTxt(DirectoryPath + logFileName );
AppendTxt(DirectoryPath +logFileName ,Str);
end
else
AppendTxt(DirectoryPath + logFileName ,Str)
end;
//追加文件内容
Procedure AppendTxt(filePath:String;LogStr:String);
Var
F:Textfile;
Begin
AssignFile(F, filePath);
Append(F);
Writeln(F, Str);
Closefile(F);
End;
//新建文件
Procedure NewTxt(filePath:String);
Var
F : Textfile;
Begin
AssignFile(F, filePath);
ReWrite(F);
Closefile(F);
End;