maxkleiner / maXbox4

code compiler script studio
GNU General Public License v3.0
23 stars 10 forks source link

FindFirst and TSearchRec #14

Closed maxkleiner closed 1 year ago

maxkleiner commented 4 years ago

I did organize a third findfirst system (FindFirst3 and TFindRec) cause the compatibility with the standard was not given:

procedure LoadFilesByMask(lst: TStrings; const SpecDir, WildCard: string); var intFound: Integer; SearchRec: TFindRec; begin lst.Clear; if FindFirst3(SpecDir + WildCard, SearchRec) then repeat lst.Add(SpecDir + SearchRec.Name); until FindNext3(SearchRec) = false; FindClose3(SearchRec); end;

Standard system:

{procedure LoadFilesByMask(lst: TStrings; const SpecDir, WildCard: string); var intFound: Integer; SearchRec: TSearchRec; begin lst.Clear; intFound := FindFirst(SpecDir + WildCard, faAnyFile, SearchRec); while intFound = 0 do begin lst.Add(SpecDir + SearchRec.Name); intFound := FindNext(SearchRec); end; FindClose(SearchRec); end; }

maxkleiner commented 1 year ago

Tested with

//Discuss the Recursion of findfile!
  Proc FindFilePattern3(root:str; pattern:str);
  var SR: TFindRec;
  begin
    root:=IncludeTrailingPathDelimiter(root);
    if FindFirst3(root+'*.*',SR) = TRue then begin
    repeat
     Application.ProcessMessages;
       if ((sr.attributes and faDirectory)= SR.Attributes) and 
         (pos('.',SR.name)=0) then
          FindFilePattern3(root+SR.Name,pattern)
       else begin
        if pos(pattern,SR.Name)>0 then 
          //Form1.ListBox1.Items.Add(Root+SR.Name);
          writeln(Root+SR.Name);
       end;
    until FindNext3(SR) = False;
      FindClose3(SR);  
    end;
  end;