function FindLastWrittenFile(Dir,Search:String):String;
Var
R:TSearchRec;
LastWrite,LastWriteAllFiles:TDateTime;
begin
Dir:=IncludeTrailingBackslash(Dir);
LastWriteAllFiles:=0;
Result:='';
if FindFirst(Dir+Search,faAnyFile-faDirectory,R)=0 then
repeat
LastWrite := FileTimeToDTime(R.FindData.ftLastWriteTime);;
if LastWrite>LastWriteAllFiles Then
begin
LastWriteAllFiles:=LastWrite;
Result:=R.Name;
end;
until FindNext(R)<>0;
FindClose(R);
end;
|