using VBScript_RegExp_55_TLB;
function get_file(folder: string; mask: string):string;
var
max_date : TdateTime;
file_date : TDateTime;
myRegExp1 : TRegExp;
mc: MatchCollection;
file_n: string;
i: integer;
SR : TSearchRec;
begin
max_date := StrToDateTime('01.01.1970 00:00:00');
myRegExp1 :=TRegExp.Create(self);
myRegExp1.IgnoreCase := true;
myRegExp1.Global := false;
myRegExp1.Pattern := mask;
file_n := '';
if FindFirst(folder+'\*.*', faAnyFile, SR) = 0 then
begin
repeat
mc:=myRegExp1.Execute(SR.Name) as MatchCollection;
if mc.Count > 0 then begin
file_date := GetFileDate(folder+'\'+SR.Name);
if file_date > max_date then begin
max_date:=file_date;
file_n := folder+'\'+SR.Name;
end;
end;
until FindNext(SR) <> 0;
FindClose(SR);
end;
result:=file_n;
end;