unit Unit1; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) ListBox1: TListBox; Button1: TButton; Edit1: TEdit; Edit2: TEdit; Label1: TLabel; Label2: TLabel; procedure Button1Click(Sender: TObject); private { Private-Deklarationen } Function LogFiles( Const path: String; Const SRec: TSearchRec ): Boolean; public { Public-Deklarationen } end; var Form1: TForm1; implementation Type TLogFunct = Function( Const path: String; Const SRec: TSearchRec ): Boolean of Object; {$R *.DFM} Procedure FindRecursive( Const path: String; Const mask: String; LogFunction: TLogFunct ); Var fullpath: String; Function Recurse( Var path: String; Const mask: String ): Boolean; Var SRec: TSearchRec; retval: Integer; oldlen: Integer; Begin Recurse := True; oldlen := Length( path ); (* phase 1, look for normal files *) retval := FindFirst( path+mask, faAnyFile, SRec ); While retval = 0 Do Begin If (SRec.Attr and (faDirectory or faVolumeID)) = 0 Then (* we found a file, not a directory or volume label, log it. Bail out if the log function returns false. *) If not LogFunction( path, SRec ) Then Begin Result := False; Break; End; retval := FindNext( SRec ); End; FindClose( SRec ); If not Result Then Exit; (* Phase II, look for subdirectories and recurse thru them *) retval := FindFirst( path+'*.*', faDirectory, SRec ); While retval = 0 Do Begin If (SRec.Attr and faDirectory) <> 0 Then (* we have a directory *) If (SRec.Name <> '.') and (SRec.Name <> '..') Then Begin path := path + SRec.Name + '\'; If not Recurse( path, mask ) Then Begin Result := False; Break; End; Delete( path, oldlen+1, 255 ); End; retval := FindNext( SRec ); End; FindClose( SRec ); End; Begin If path = '' Then GetDir(0, fullpath) Else fullpath := path; If fullpath[Length(fullpath)] <> '\' Then fullpath := fullpath + '\'; If mask = '' Then Recurse( fullpath, '*.*' ) Else Recurse( fullpath, mask ); End; Function TForm1.LogFiles( Const path: String; Const SRec: TSearchRec ): Boolean; Begin Listbox1.Items.Add( path+SRec.Name ); Result := True; (* proceeed with recursion *) End; procedure TForm1.Button1Click(Sender: TObject); begin ListBox1.Clear; Listbox1.Perform( WM_SETREDRAW, 0, 0 ); FindRecursive( Edit1.Text, Edit2.Text, LogFiles ); Listbox1.Perform( WM_SETREDRAW, 1, 0 ); Listbox1.Refresh; end; end.