Einzelnen Beitrag anzeigen

Benutzerbild von CReber
CReber

Registriert seit: 26. Nov 2003
Ort: Berlin
343 Beiträge
 
Delphi 2006 Professional
 
#2

Re: Probleme mit Ordner auflisten

  Alt 22. Mai 2004, 00:36
Dank der Code-Lib von Herrn Vollmer hab ich jetzt nen Quellcode gefunden


Delphi-Quellcode:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ActiveX, ShlObj;

type
  TForm1 = class(TForm)
    Button1: TButton;
    ListBox1: TListBox;
    procedure Button1Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;
  liste: TStringList;

implementation

{$R *.dfm}

procedure FindeDateien(aPath, aFindMask: String; aWithSub: Boolean; aResult: tStrings);
Var
  FindRec: tSearchRec;
Begin
  If (aPath = '') or (aFindMask = '') or Not Assigned (aResult) Then
    Exit;

  If aPath[Length (aPath)] <> '\Then
    aPath := aPath + '\';

   If FindFirst (aPath + aFindMask, faAnyFile, FindRec) = 0 Then
    Repeat
      If (FindRec.Name <> '.') and (FindRec.Name <> '..') Then
       aResult.Add (aPath + FindRec.Name);
    Until FindNext (FindRec) <> 0;

  FindClose (FindRec);

   If Not aWithSub Then
    Exit;

  If FindFirst (aPath + '*.*', faAnyFile, FindRec) = 0 Then
    Repeat
      If (FindRec.Name <> '.') and (FindRec.Name <> '..') Then
         If Boolean (FindRec.Attr and faDirectory) Then
           FindeDateien (aPath + FindRec.Name, aFindMask, aWithSub, aResult);
    Until FindNext (FindRec) <> 0;

   FindClose (FindRec);
End;

procedure TForm1.Button1Click(Sender: TObject);
  var
    x: integer;
begin
  liste := tstringlist.create;
  FindeDateien('c:\Programme', '*.*', True, liste);
  for x := 0 to liste.count - 1 do
    ListBox1.Items.Add(liste[x]);

end;

end.
Ah grad noch nen Fehler von dem Quellcode gefunden ! Es werden Ordner UND Dateien aufgelistet... Statt nur Dateien! Ma gucken ob ich den Fehler noch finde...


... gefunden

Delphi-Quellcode:
      If (FindRec.Name <> '.') and (FindRec.Name <> '..') Then
        begin
          if DirectoryExists(aPath + FindRec.Name)=False then
            aResult.Add (aPath + FindRec.Name);
        end;
Christian Reber
  Mit Zitat antworten Zitat