procedure GetFilesInDirectory(Directory: string; const Mask: string;
List: TStrings;
WithSubDirs, ClearList: Boolean);
procedure ScanDir(const Directory: string);
var
SR: TSearchRec;
begin
if FindFirst(Directory + Mask, faAnyFile and not faDirectory, SR) = 0 then try
repeat
List.Add(Directory + SR.Name)
until FindNext(SR) <> 0;
finally
FindClose(SR);
end;
if WithSubDirs then begin
if FindFirst(Directory + '*.*', faAnyFile, SR) = 0 then try
repeat
if ((SR.attr and faDirectory) = faDirectory) and
(SR.Name <> '.') and (SR.Name <> '..') then
ScanDir(Directory + SR.Name + '/');
until FindNext(SR) <> 0;
finally
FindClose(SR);
end;
end;
end;
begin
List.BeginUpdate;
try
if ClearList then
List.Clear;
if Directory = '' then Exit;
if Directory[Length(Directory)] <> '/' then
Directory := Directory + '/';
ScanDir(Directory);
finally
List.EndUpdate;
end;
end;
Beispiel :
procedure TForm1.Button1Click(Sender: TObject);
begin
GetFilesInDirectory('C:/Windows/temp/', '*.*', // HIER KANN AUCH SPEZIFISCH NACH DATEIEN GESUCHT WERDEN.
ListBox1.Items, False, True);
end;
Keine Kommentare:
Kommentar veröffentlichen