Fandom

Delphi Programming

Find Files with recursion (Code Snippet)

2,918pages on
this wiki
Add New Page
Talk0 Share

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.

type
  TFindFileProc = procedure(const FoundPath, FoundFile: String) of Object;

procedure MultipleFileSearch(const PathName, FileName : string; const SubDirs: Boolean; OnFind: TFindFileProc);
var
  Rec: TSearchRec;
  Path: string;
begin
  Path := IncludeTrailingBackslash(PathName);
  if FindFirst(Path + FileName, faAnyFile - faDirectory, Rec) = 0 then
  try
    repeat
      OnFind(Path, Rec.Name);
    until FindNext(Rec) <> 0;
  finally
    FindClose(Rec);
  end;

  If not SubDirs then Exit;

  if FindFirst(Path + '*.*', faDirectory, Rec) = 0 then
  try
    repeat
      if ((Rec.Attr and faDirectory) <> 0) and (Rec.Name<>'.') and (Rec.Name<>'..') then
        MultipleFileSearch(Path + Rec.Name, FileName, True, OnFind);
    until FindNext(Rec) <> 0;
  finally
    FindClose(Rec);
  end;
end; //procedure FileSearch

External linksEdit


Code Snippets
DatabasesFiles and I/OForms/WindowsGraphicsNetworkingMath and AlgorithmsMiscellaneousMultimediaSystemVCL

Also on Fandom

Random Wiki