Jetzt sieht der Code wie folgt aus:
Delphi-Quellcode:
function TForm1.FindAllFiles2(RootFolder: string; Mask: string = '*.*'; Recurse: Boolean = True): TListOfStrings;
var
SR: TSearchRec;
SubList: TListOfStrings;
begin
Result := TListOfStrings.Create(100);
SubList := TListOfStrings.Create(100);
if AnsiLastChar(RootFolder)^ <> '\' then
RootFolder := RootFolder + '\';
try
Result.AddString(RootFolder);
if FindFirst(RootFolder + Mask, faAnyFile, SR) = 0 then
try
repeat
if (SR.Name <> '.') and (SR.Name <> '..') then
begin
Result.AddString(RootFolder + SR.Name);
if (SR.Attr and faDirectory = faDirectory) then
SubList := FindAllFiles2(RootFolder + SR.Name, Mask, Recurse);
end;
until
FindNext(SR) <> 0;
Result.AddListOfStrings(SubList);
finally
FindClose(SR);
end;
finally
SubList.Free;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var a: cardinal; b: tListOfStrings; c: cardinal;
begin
c := 5;
a := gettickcount;
for c := 0 to c do
begin
b := FindAllFiles2('C:\');
b.Free;
end;
caption := inttostr(gettickcount - a);
end;
RAM vorher 2,2 MB
RAM nachher 15 MB
irgendwo ist da noch ein Fehler, den ich nicht finde...