Jump to content

Delete cache...

Eugeniusz Rink

Recommended Posts

  • 1 year later...
  • 6 months later...
1 hour ago, artem_niko said:

Anybody have ideas?

Hi, I don't know what you need to do to make unigui clear cache files, but you can create your own function that clears files older than a few days when uniGui Server starts or using TThreatTimer

here's a few examples: https://stackoverflow.com/questions/54321253/delphi-delete-files-in-a-directory-older-than-x-days-and-or-having-a-special-fi


search results: https://www.google.com/search?q=delphi+clear+older+files&oq=delphi+clear+older+files&aqs=chrome..69i57j0i22i30j0i390.6735j0j7&sourceid=chrome&ie=UTF-8

Link to comment
Share on other sites

On 11/19/2022 at 4:28 PM, eduardosuruagy said:

I was wondering how you guys managed to delete cache folders in a certain number of days?

I use this in my desktop application to only delete files from a temporary directory.

// =================================================================
// Delete files (mask) from a directory that are older than X days
// Returns number of files deleted, but will raise an exception if
// unable to delete a file (eg. Read Only attribute) if
// AFailOnError is true.
// NOTE : AOlderThanDays = 0 will delete ALL files matching mask
// =================================================================

function sysDeleteOlderFiles(const AFileMask : AnsiString; AOlderThanDays : word; AFailOnError : boolean = false) : AnsiString;
  rDirInfo : TSearchRec;
  iResult,iError : integer;
  dtFileDate,dtNow : TDateTime;
  sFilePath,sErrMess : string;
  label ENDAll;
  sFunctionName := 'sysDeleteOlderFiles';
  sErrMess := '';
  iResult := 0;
  dtNow := Date;
  sFilePath := ExtractFilePath(AFileMask);
  iError := FindFirst(AFileMask,faAnyFile,rDirInfo);

  // Itterate thru files found with mask
  while iError = 0 do begin
    // Eclude Directories
    if (rDirInfo.Name <> '.')
    and (rDirInfo.Name <> '..')
    and (rDirInfo.Attr
          and faDirectory  <> faDirectory) then begin
      dtFileDate := FileDateToDateTime(rDirInfo.Time);

      // Does the file meet deletion days criteria ?
      if trunc(dtNow - dtFileDate) + 1  >= AOlderThanDays then begin
        // Delete the file - raise exception if fail and AFailOnError set
        if not DeleteFile (sFilePath + rDirInfo.Name)
        and AFailOnError then begin
           sErrMess := 'Failed on file: ' + sFilePath + rDirInfo.Name + '\n ' + SysErrorMessage(GetLastError);
           raise Exception.Create(sErrMess);


    iError := FindNext(rDirInfo);

  EndAll : begin
      if sErrMess <> '' then
           Result := sErrMess
      else Result := '';//IntToStr (iResult);


Link to comment
Share on other sites

  • 1 month later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...