Einfach den Code von
FindAllFiles so abändern, dass er nur die Ordner auflistet.
Nachtrag: Schnell hingetippt (nicht sehr performant):
Delphi-Quellcode:
function TForm1.IsInListBox(FileName: string): boolean;
var i: integer;
begin
result := false;
for i := 0 to ListBox1.Items.Count - 1 do
begin
if ListBox1.Items[i] = FileName then
begin
result := true;
break;
end;
end;
end;
procedure TForm1.FindAllFolders(RootFolder: 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
if (SR.Name <> '.') and (SR.Name <> '..') then
begin
FindAllFolders(RootFolder + SR.Name, Recurse);
if not IsInListBox(RootFolder) then
begin
ListBox1.Items.Add(RootFolder);
Application.ProcessMessages;
end;
end;
until FindNext(SR) <> 0;
finally
FindClose(SR);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
FindAllFolders('c:\');
end;