?
Solved

Date sorted FileList

Posted on 2003-02-28
2
Medium Priority
?
2,556 Views
Last Modified: 2008-03-17
Hi;

i need a File list sorted by date ascending.

Does anyone knows a component or piece of code i can use for that?

Im using delphi 5.

TIA.
0
Comment
Question by:arturop
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 7

Expert Comment

by:Motaz
ID: 8044163
I'm writing code now..
0
 
LVL 7

Accepted Solution

by:
Motaz earned 200 total points
ID: 8044217
finished..

Drop a ListBox and a Button, and write this code in buttons onClick:

procedure TForm1.Button1Click(Sender: TObject);
var
  Rec: TSearchRec;
  FileList: array of string;
  DateList: array of TDateTime;
  i: Integer;
  Done: Boolean;
  TempName: string;
  TempDate: TDateTime;
begin
  // Get files list
  if FindFirst('c:\*.*', faAnyFile, Rec) = 0 then
  repeat
    Setlength(FileList, Length(FileList) + 1);
    Setlength(DateList, Length(DateList) + 1);
    FileList[High(FileList)]:= Rec.Name;
    DateList[High(DateList)]:= FileDateToDateTime(Rec.Time);
  until FindNext(Rec) <> 0;
  FindClose(Rec);

  // Sort
  // Bubble sort
  repeat
    Done:= True;
    for i:= 0 to High(FileList) - 1 do
      if DateList[i] > DateList[i + 1] then
      begin
        Done:= False;
        TempName:= FileList[i];
        FileList[i]:= FileList[i + 1];
        FileList[i + 1]:= TempName;

        TempDate:= DateList[i];
        DateList[i]:= DateList[i + 1];
        DateList[i + 1]:= TempDate;

      end;

  until Done;

  // Show in list
  ListBox1.Clear;
  for i:= 0 to High(FileList) do
    ListBox1.Items.Add(FileList[i] + '   ' + DateTimeToStr(DateList[i]));
end;


If you want descending sort then invert the comparison operator to <

      if DateList[i] < DateList[i + 1] then


Motaz
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question