unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 =
class(TForm)
ListBox1: TListBox;
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure ListBox1DblClick(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
type
TListEntry =
record
FullFilename:
string[255]
end;
// Pointer to data record
PListEntry = ^TListEntry;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure GetFilesInDirectory(ADirectory:
string; AMask:
String; AList: TStrings; ARekursiv: Boolean);
var
Entry: PListEntry;
SR: TSearchRec;
begin
if (ADirectory <> '
')
and (ADirectory[length(ADirectory)] <> '
\')
then
ADirectory := ADirectory + '
\';
if (FindFirst(ADirectory + AMask, faAnyFile
and not faDirectory, SR) = 0)
then begin
repeat
if (SR.Attr
and faDirectory) = 0
then
begin
new(Entry);
Entry^.FullFilename := ADirectory + SR.
Name;
AList.AddObject(SR.
Name, TObject(Entry))
//AList.Add(ADirectory+SR.Name)
end;
until FindNext(SR) <> 0;
FindClose(SR);
end;
if ARekursiv
then
if (FindFirst(ADirectory + '
*.*', faDirectory, SR) = 0)
then
begin
repeat
if (SR.
Name <> '
.')
and (SR.
Name <> '
..')
then
GetFilesInDirectory(ADirectory + SR.
Name, AMask, AList, True);
until FindNext(SR) <> 0;
FindClose(SR);
end;
end;
procedure ShowFullFilename(
const ID: Integer);
var
Filename:
string;
begin
Filename := PListEntry(Form1.ListBox1.Items.Objects[ID])^.FullFilename;
ShowMessage(Filename);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
ListBox1.Items.BeginUpdate;
GetFilesInDirectory('
C:\...\Eigene Dateien', '
*.*', ListBox1.Items, True);
ListBox1.Items.EndUpdate;
end;
procedure TForm1.ListBox1DblClick(Sender: TObject);
begin
if ListBox1.ItemIndex <> -1
then
ShowFullFilename(ListBox1.ItemIndex);
end;
end.