GetFiles

How to recusively list all files in directories.

procedure GetFiles(Result: TStrings; Path: string; IncludePath: Boolean = False);

var

  R: Integer;

  SR: TSearchRec;

  ThePath: string;

begin

  Assert(Result <> nil, 'Result is Nill');

  ThePath := ExtractFilePath(Path);

  ThePath := IncludeTrailingBackSlash(ThePath);

  R := FindFirst(Path, faAnyFile, SR);

  while R = 0 do

  begin

    if IncludePath then

      Result.Add(ThePath + SR.Name)

    else

      Result.Add(SR.Name);

    R := FindNext(SR);

  end;

  FindClose(SR);

end;

 

Share this article!

Follow us!

Find more helpful articles: