Autor Beitrag
hibbert
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1007

WinServer2003, Win XP, Linux
D6 Pers, D05
BeitragVerfasst: Mo 15.03.04 15:15 
Hi,
mit diesem QT, kann ich bestimmte Dateien in eines Verzeichnisses auflisten:
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
procedure FindFiles (aPath, aFindMask: String; aWithSub: Boolean; aResult: tStrings);
Var
  FindRec: tSearchRec;
Begin
  // Wenn die Stringliste nil ist oder aPath oder aFind nicht angegeben ist
  // dann raus
  If (aPath = '') or (aFindMask = '') or Not Assigned (aResult) Then
    Exit;

  // Wenn am Ende der Pfadangabe noch kein \ steht, dieses hinzufügen
  If aPath[Length (aPath)] <> '\' Then
    aPath := aPath + '\';

  // Im aktuellen Verzeichnis nach der Datei suchen
  If FindFirst (aPath + aFindMask, faAnyFile, FindRec) = 0 Then
    Repeat
      If (FindRec.Name <> '.') and (FindRec.Name <> '..') Then
        // ...Ergebnis in die Stringlist einfügen
        aResult.Add (aPath + FindRec.Name);
    Until FindNext (FindRec) <> 0;

  FindClose (FindRec);

  // Wenn nicht in Unterverzeichnissen gesucht werden soll dann raus
  If Not aWithSub Then
    Exit;

  // In Unterverzeichnissen weiter suchen
  If FindFirst (aPath + '*.*', faAnyFile, FindRec) = 0 Then
    Repeat
      If (FindRec.Name <> '.') and (FindRec.Name <> '..') Then
        // Feststellen, ob es sich um ein Verzeichnis handelt
        If Boolean (FindRec.Attr and faDirectory) Then
          // Funktion erneut aufrufen, um Verzeichnis zu durchsuchen (Rekursion)
          FindFiles (aPath + FindRec.Name, aFindMask, aWithSub, aResult);
    Until FindNext (FindRec) <> 0;

   FindClose (FindRec);
End;
...
FindFiles ('C:\Windows','*.txt', false, form1.ListBox1.Items);


Nun möchte ich aber die Datein in der Listbox nach dem änderungs bzw. erstelldatum sortiert haben.

ist sowas möglich?

thx hibbert

Moderiert von user profile iconTino: Verschoben.

_________________
I kunnen väl svara endast ja eller nej
Om i viljen eller nej
StefanH
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1144

Win XP
D5 Standard, D7 Pers, D2005 Pers
BeitragVerfasst: Mo 15.03.04 16:22 
FileDate

oder so könnt dir helfen... für jedes Ding nehmen und dann sortieren :nut:

_________________
"Als es noch keine Computer gab, war das Programmieren noch relativ einfach."(Edsger W. Dijkstra)
"Ich bin nicht von Sinnen, sondern ich rede wahre und vernünftige Worte." (Paulus)
hibbert Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1007

WinServer2003, Win XP, Linux
D6 Pers, D05
BeitragVerfasst: Mo 15.03.04 19:51 
ok,
ich habe mal im Forum nach FileDate gesucht, habe aber nur gefunden, wie man das "Alter" von verezeichnissen ausließt. (Topic)

Nun möchte ich dieses aber gerne auf dateien anwenden und diese auch in der richtigen reiehnfolge sortiert haben, also die datei die zuerst erstellt wurde usw.

Ach noch was: es handelt sich hier um sekunden, die erfasst werden sollen.

thx hibbert

_________________
I kunnen väl svara endast ja eller nej
Om i viljen eller nej
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Mo 15.03.04 20:04 
Hallo!

Das Dateidatum und die Zeit kennst Du doch aus Deinem FindRec. Und zwar so:
ausblenden Delphi-Quelltext
1:
FileDateToDateTime(FindRec.Time)					


Dann legst Du einfach parallel zu der Liste mit den Namen eine Liste mit den Daten an. Mit der Liste kannst Du die Position bestimmen, an der eine Datei eingefügt werden muss, damit die Reihenfolge korrekt ist.

Ich hoffe, das hilft (und funktioniert überhaupt). :-)

MfG
Peter

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
hibbert Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1007

WinServer2003, Win XP, Linux
D6 Pers, D05
BeitragVerfasst: Di 16.03.04 17:21 
jo danke das funzt hervorragend. :D

THX !!

hibbert

_________________
I kunnen väl svara endast ja eller nej
Om i viljen eller nej