Forum > General

(SOLVED.. Error by myself) FindAllFiles cumulates its results

(1/1)

ratmalwer:
Fatal error in FindAllFiles

It took me ages to find this, as I suspected the problem somwhere else.

Now I realised that the function FindAllFiles called repeatedly does cumulate its result.
It does not matter if I have one or more stringlists I fill alternatively.

How do I implement this correctly that it clears the values?


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.fileListeErstellen;var   myStringList: TStringList;   myStringList2: TStringList;begin   myStringList := TStringList.Create;  myStringList2 := TStringList.Create;   try    execution := execution + 1;    FindAllFiles(myStringList, editQuellpfad.Text, '*.*', true);     showmessage(inttostr(myStringList.Count));//shows 5 in first execution, shows 10 in the second execution     if execution > 1 then begin       FindAllFiles(myStringList2, editQuellpfad.Text, '*.*', true);       showmessage('Stringlist2: ' + inttostr(myStringList2.Count));//is not called in first execution, shows 10 in the second execution    end;  finally    myStringList.Free;    myStringList2.Free;   end; 

howardpc:
You don't show where execution is set, or what determines its value.

This routine gives identical file counts, as expected:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.FindFilesButtonClick(Sender: TObject);var  sl1, sl2: TStringList;  path: String;begin  path:=GetCurrentDir;  sl1:=TStringList.Create;  try    Memo.Clear;    Memo.Lines.Add('Call #1');    FindAllFiles(sl1, path, '*', True);    Memo.Lines.Assign(sl1);    Memo.Lines.Add('--- Call #1 Count=%d ---',[sl1.Count]);    sl2:=TStringList.Create;    try      Memo.Lines.Add('Call #2');      FindAllFiles(sl2, path, '*', True);      Memo.Lines.AddStrings(sl2);      Memo.Lines.Add('--- Call #2 Count=%d ---',[sl2.Count]);    finally      sl2.Free;    end;  finally    sl1.Free;  end;end;

ratmalwer:
thanks howard

as I read my results I realised that the third message showed 10 but by my (errornes) suspichous had to be 15. So I looked it over again.  - The reason was, that my testdirectories had identical Files (or almost) as I copied them so I cumulated it myself.
Sorry I stole your time - but I really thougt it is a serious error.

Markus

Navigation

[0] Message Index

Go to full version