Hola shoulder.
Código Delphi
[-]
...
implementation
uses Contnrs, DateUtils;
type
TClassFile = class
Name : string;
Date : TDateTime;
end;
procedure SortFilesByDate( Path: string; TS: TStrings );
function Compare( a, b: Pointer ): Integer;
begin
Result:= CompareDateTime( TClassFile(a).Date, TClassFile(b).Date );
end;
var
Lista: TObjectList;
cFile: TClassFile;
SR : TSearchRec;
i : Integer;
begin
Path := IncludeTrailingPathDelimiter( Path );
if FindFirst( Path + '*.*', faArchive, SR ) = 0 then
begin
Lista:= TObjectList.Create;
try
repeat
cFile := TClassFile.Create;
cFile.Name := SR.Name;
cFile.Date := FileDateToDatetime( SR.Time );
Lista.Add( cFile );
until FindNext( SR ) <> 0;
FindClose( SR );
Lista.Sort( @Compare );
for i:= 0 to Lista.Count-1 do
TS.Add( TClassFile(Lista[i]).Name );
finally
Lista.Free;
end;
end;
end;
Ejemplo de uso:
Código Delphi
[-]
procedure TForm1.btnSortClick(Sender: TObject);
begin
SortFilesByDate( 'C:\Una_Carpeta', ListBox1.Items );
end;
Saludos