Autor Beitrag
Blackheart
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 164

ME
D3Prof.-D6Standard
BeitragVerfasst: Mo 21.06.04 16:28 
Hallo Leute

Ich hab da folgendes Problem. Ich würde mir gern in einer Listbox die gesamten Dateien eines Laufwerks anzeigen lassen. Nun hab ich das Problem das er die Erste Datei immer überspringt und ich weiß nicht warum!

Zum Beispiel bei einer Audio CD zeigt er erst ab Titel 2 an. Bei einer MP3 CD wird der Erste Ordner komplett übersprungen den Rest zeigt er korekt an.

Hat einer ne' Ahnung woran das liegen könnte.

Source:

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:
42:
43:
procedure FindAllFiles(dir:String;var output:TStringlist;var count:integer);
var
    tr:TsearchRec;
begin
    FindFirst(dir+'*.*',faAnyFile,tr);
    while FindNext(tr)=0 do
        begin
        if not (tr.Name='..') then
        begin
         if (tr.Attr and faDirectory > 0) then
         FindAllFiles(dir+tr.Name+'\',output,count) else
            begin
              inc(count);
              output.Add(dir+tr.Name);
            end;
        end;
    end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
    x,xx:integer;
    y    :real;
    s,Laufwerk    :string;
    d    :TStringList;

begin

  Laufwerk:=DriveComboBox1.Drive;
  d := TstringList.Create;
  xx:=0;
  x :=GetTickCount;
  FindAllFiles(Laufwerk+':\',d,xx);
  y :=(GetTickCount-x)/1000;
  str(y:4:2,s);

  s :='Der Suchvorgang hat '+s+' Sekunden gedauert'+#13#10+
       'und '+inttostr(xx)+' Datein wurden gefunden';
  showmessage(s);

  Listbox1.Items:=d;
  d.Free;
end;


Moderiert von user profile iconTino: Code- durch Delphi-Tags ersetzt.
Moderiert von user profile iconTino: Absätze formatiert.
obbschtkuche
Gast
Erhaltene Danke: 1



BeitragVerfasst: Mo 21.06.04 16:52 
imho müsste es so aussehen:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
    FindFirst(dir+'*.*',faAnyFile,tr);
    repeat
        if not (tr.Name='..') then
        begin
         if (tr.Attr and faDirectory > 0) then
         FindAllFiles(dir+tr.Name+'\',output,count) else
            begin
              inc(count);
              output.Add(dir+tr.Name);
            end;
        end;
    until FindNext(tr) <> 0;
MathiasSimmack
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Mo 21.06.04 21:03 
Mit while geht´s auch, allerdings darf man dann natürlich nicht "FindNext" heranziehen. So wär´s besser:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
res := FindFirst(...);
while(res = 0) do
begin
  { ... }

  res := FindNext(...);
end;
Brueggendiek
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 304

Win 98, Win98SE, Win XP Home
D5 Std
BeitragVerfasst: Mo 21.06.04 22:02 
Hallo!

Soweit - so gut. Nur vermisse ich noch was: Wo ist das FindClose?
Sonst müällst Du Dir den Speicher zu bzw. die Windows-Ressouzrcen werden knapp.

Gruß

Dietmar Brüggendiek
Tino
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Veteran
Beiträge: 9839
Erhaltene Danke: 45

Windows 8.1
Delphi XE4
BeitragVerfasst: Di 22.06.04 08:40 
Hallo!

Schau dir doch auch mal unsere Beispiele in der FAQ an: Suche in: Delphi-Library FINDFIRST UND FINDNEXT.

Gruß
Tino
Blackheart Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 164

ME
D3Prof.-D6Standard
BeitragVerfasst: Di 22.06.04 10:39 
Danke Euch für die Schnelle Antwort !
Hab nochmal unter dem Link von Tino nachgeschaut, war genau das was ich brauchte.
maximus
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 896

Win XP, Suse 8.1
Delphi 4/7/8 alles prof
BeitragVerfasst: Di 22.06.04 11:03 
Oder du nimmst diese unit: www.delphi-forum.de/viewtopic.php?t=18948 die kann das alles vollautomatisch :wink:

_________________
mfg.
mâximôv