Var iList, iRetry: Integer; tmpChecksum, tmpEntry, tmpFile, tmpDateTimeStr: String; tmpList, tmpDates: TStringList; tmpSuccess: Boolean; tmpDateTime: TDateTime; Const ctCleanupDays = 5; ctChecksumFile = 'C:\Test\Customer\Data\Checksum.txt'; Begin psExitCode:= 0; tmpChecksum := ''; tmpFile := psFilePath + psFileName; tmpSuccess := False; // ... add your code here tmpList := TStringList.Create; Try If FileExists(ctChecksumFile) Then Begin Try tmpList.LoadFromFile(ctChecksumFile); tmpSuccess := True; psLogWrite(1, '', 'LoadFromFile ' + ctChecksumFile + ' Successfull'); Except psLogWrite(1, '', 'LoadFromFile exception of ' + ctChecksumFile); End; End Else Begin tmpSuccess := True; psLogWrite(1, '', 'Checksum file does not yet exist'); End; // If tmpSuccess Then Begin tmpChecksum := psGetFileChecksum(tmpFile, 1); // SHA256 If tmpChecksum <> '' Then Begin If Pos(psFileName + '|', tmpList.Text) <> 0 Then Begin For iList := 0 to (tmpList.Count-1) Do Begin If Pos(psFileName + '|', tmpList.Strings[iList]) <> 0 Then Begin tmpList.Strings[iList] := psFileName + '|' + tmpchecksum + '|' + FormatDateTime('YYYY-MM-DD HH:NN:SS', Now); End; End; End Else tmpList.Add(psFileName + '|' + tmpChecksum + '|' + FormatDateTime('YYYY-MM-DD HH:NN:SS', Now)); // Cleanup Old Entries For iList := (tmpList.Count-1) DownTo 0 Do Begin tmpEntry := tmpList.Strings[iList]; tmpDates := psDelimitedTextAsList('|', tmpEntry); Try If tmpDates.Count > 2 Then Begin tmpDateTimeStr := tmpDates.Strings[2]; psLogWrite(1, '', 'Cleanup, Found DateTime entry: ' + tmpDateTimeStr); tmpDateTime := psStrToDateTime(tmpDateTimeStr, 'YYYY-MM-DD', 'HH:NN:SS', '-', ':'); If tmpDateTime <> 0 Then Begin psLogWrite(1, '', 'Cleanup, DateTime conversion successful'); If tmpDateTime < psIncDay(Now, -ctCleanupDays) Then Begin tmpList.Delete(iList); psLogWrite(1, '', 'Cleanup, Deleted entry: ' + tmpEntry); End; End Else psLogWrite(1, '', 'Cleanup, DateTime conversion error of ' + tmpDateTimeStr); End; Finally tmpDates.Free; End; End; // Save To File iRetry := 0; tmpSuccess := False; Repeat iRetry := iRetry + 1; Try If psSaveTxt2File(tmpList.Text, ctChecksumFile, 'utf-8', True) Then Begin psLogWrite(1, '', 'SaveToFile ' + ctChecksumFile + ' successful'); tmpSuccess := True; psExitCode := 1; End Else psLogWrite(1, '', 'SaveToFile ' + ctChecksumFile + ' error'); Except psLogWrite(1, '', 'SaveToFile exception of ' + ctChecksumFile); End; Until (iRetry = 3) or tmpSuccess; End Else psLogWrite(1, '', 'Error, could not calculate checksum of ' + ctChecksumFile); End Else psLogWrite(1, '', 'Error, could not load: ' + ctChecksumFile); Finally tmpList.Free; End; End.