Delphi: 删除目录中早于 X 天 and/or 且具有特殊文件掩码 (*.xxx) 的文件

Delphi: Delete files in a directory older than X days and/or having a special file mask (*.xxx)

语言: Delphi 10.1 柏林

问题:
有一个包含测量文件 (*.csv) 和其他文件的目录。
每隔几个小时就会创建一个新的测量文件。
我需要删除该文件夹中超过特定​​天数的所有 .csv 文件的可能性。不应触摸所有其他文件类型。

问题:
Delphi 中是否有任何内置函数可以完成这项工作?如果没有,解决这个问题的有效方法是什么?

我没有找到针对该特定问题的 Delphi 内置函数。
这个功能对我有用:

function TUtilities.DeleteFilesOlderThanXDays(
    Path: string;
    DaysOld: integer = 0; // 0 => Delete every file, ignoring the file age
    FileMask: string = '*.*'): integer;
var
  iFindResult : integer;
  SearchRecord : tSearchRec;
  iFilesDeleted: integer;
begin
  iFilesDeleted := 0;
  iFindResult := FindFirst(TPath.Combine(Path, FileMask), faAnyFile, SearchRecord);
  if iFindResult = 0 then begin
    while iFindResult = 0 do begin
      if ((SearchRecord.Attr and faDirectory) = 0) then begin
        if (FileDateToDateTime(SearchRecord.Time) < Now - DaysOld) or (DaysOld = 0) then begin
          DeleteFile(TPath.Combine(Path, SearchRecord.Name));
          iFilesDeleted := iFilesDeleted + 1;
        end;
      end;
      iFindResult := FindNext(SearchRecord);
    end;
    FindClose(SearchRecord);
  end;
  Result := iFilesDeleted;
end;
procedure DeleteFilesOlderThan(
  const Days: Integer;
  const Path: string;
  const SearchPattern: string = '*.*');
var
  FileName: string;
  OlderThan: TDateTime;
begin
  Assert(Days >= 0);
  OlderThan := Now() - Days;
  for FileName in TDirectory.GetFiles(Path, SearchPattern) do
    if TFile.GetCreationTime(FileName) < OlderThan then
      TFile.Delete(FileName);
end;