Thema: Delphi Funktion erweitern

Einzelnen Beitrag anzeigen

Benutzerbild von himitsu
himitsu

Registriert seit: 11. Okt 2003
Ort: Elbflorenz
44.184 Beiträge
 
Delphi 12 Athens
 
#6

AW: Funktion erweitern

  Alt 20. Jun 2010, 21:56
@Teekeks:
* nicht das Delphi-Referenz durchsuchenFindClose vergessen
* die For-Schleife brauchst du nicht mit diesem IF absichern (ist da schon eingebaut)
* und mal sehn was du zum Rest sagst
Delphi-Quellcode:
uses StrUtils;

procedure TForm1.scan(path: string);
var SR: TSearchRec;
    tmparray: array of string;
    i: integer;
    s: string;
begin
    SetLength(tmparray,0);
    if FindFirst(path+'*', faAnyFile, SR) = 0 then
    begin
        repeat
            if not AnsiMatchStr(SR.Name, [',', '.', '..']) then
                if SR.Attr and faDirectory = 0 then
                begin
                    if AnsiMatchText(ExtractFileExt(SR.Name), ['.mp3', '.ogg', '.aac', '.wav']) then
                    begin
                        SetLength(tmparray, Length(tmparray) + 1);
                        tmparray[High(tmparray)] := SR.Name;
                    end;
                end
                else
                    scan(path + SR.Name + '/');
         until FindNext(SR) <> 0;
         FindClose(SR);
    end;
    for i := 0 to High(tmparray) do
    begin
      //die Titel in diesem Ordner...
    end;
end;
@Muellermilchtrinker:
Delphi-Quellcode:
procedure TForm1.scan(path: string; parent: TTreeNode = nil);
var SR: TSearchRec;
  s: String;
begin
  SetLength(tmparray,0);
  if FindFirst(path + '*', faAnyFile, SR) = 0 then
    try
      repeat
        if (SR.Name <> '.') and (SR.Name <> '..') then
          if SR.Attr and faDirectory = 0 then
          begin
            TreeView1.Items.AddChild(parent, SR.Name);
            //s := SR.Name;
            //if not DateiendungAnzeigen then
            // s := ChangeFileExt(s, '');
            //TreeView1.Items.AddChild(parent, S);
          end
          else
            scan(path + SR.Name + '/', TreeView1.Items.AddChild(parent, SR.Name));
      until FindNext(SR) <> 0;
    finally
      FindClose(SR);
    end;
end;

scan('C:\');
$2B or not $2B
  Mit Zitat antworten Zitat