unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 =
class(TForm)
Button1: TButton;
ListBox1: TListBox;
Edit1: TEdit;
OpenDialog1: TOpenDialog;
procedure Button1Click(Sender: TObject);
procedure ListBox1DrawItem(Control: TWinControl;
Index: Integer;
aRect: TRect; State: TOwnerDrawState);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure FindAllFiles(
var FileList: TStrings; RootFolder:
string; Mask:
string =
'
*.*'; Recurse: Boolean = True);
var
SR: TSearchRec;
begin
if AnsiLastChar(RootFolder)^ <> '
\'
then
RootFolder := RootFolder + '
\';
if Recurse
then
if FindFirst(RootFolder + '
*.*', faAnyFile, SR) = 0
then
try
repeat
if SR.Attr
and faDirectory = faDirectory
then
// --> ein Verzeichnis wurde gefunden
// der Verzeichnisname steht in SR.Name
// der vollständige Verzeichnisname (inkl. darüberliegender Pfade) ist
// RootFolder + SR.Name
if (SR.
Name <> '
.')
and (SR.
Name <> '
..')
then
FindAllFiles(FileList, RootFolder + SR.
Name, Mask, Recurse);
until FindNext(SR) <> 0;
finally
FindClose(SR);
end;
if FindFirst(RootFolder + Mask, faAnyFile, SR) = 0
then
try
repeat
if SR.Attr
and faDirectory <> faDirectory
then
begin
// --> eine Datei wurde gefunden
// der Dateiname steht in SR.Name
// der vollständige Dateiname (inkl. Pfadangabe) ist
// RootFolder + SR.Name
FileList.Add(RootFolder + SR.
Name);
end;
until FindNext(SR) <> 0;
finally
FindClose(SR);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
list:TStrings;
begin
list:=TSTringlist.Create;
if OpenDialog1.Execute
then
begin
Edit1.Text:=ExtractFileDir(OpenDialog1.FileName)+'
\';
FindAllFiles(list,Edit1.Text,'
*.bmp',false);
Form1.ListBox1.Items:=list;
end;
end;
procedure TForm1.ListBox1DrawItem(Control: TWinControl;
Index: Integer;
aRect: TRect; State: TOwnerDrawState);
var
Bit : TBitmap;
begin
with TListBox(Control)
do
begin
Bit.LoadFromFile(Items[
Index]);
Canvas.StretchDraw(Rect(aRect.Left+2, aRect.Top+2, aRect.Left+ItemHeight-4, aRect.Bottom-2), Bit);
Canvas.TextOut(aRect.Left+ItemHeight, aRect.Top+2, Items[
Index])
end;
end;
end.