Wikia

Delphi Programming

Find Files with recursion (Code Snippet)

2,918pages on
this wiki
Talk0
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

Around Wikia's network

Random Wiki