Task

Walk a given directory tree and print files matching a given pattern.


Note: This task is for recursive methods.   These tasks should read an entire directory tree, not a single directory.


Note: Please be careful when running any code examples found here.



Related task

   Walk a directory/Non-recursively   (read a single directory). 


 
program Walk_a_directory;
 
{$APPTYPE CONSOLE}
{$R *.res}
 
uses
  System.IOUtils;
 
var
  Files: TArray<string>;
  FileName, Directory: string;
 
begin
  Directory := TDirectory.GetCurrentDirectory;  // dir = '.', work to
  Files := TDirectory.GetFiles(Directory, '*.*', TSearchOption.soAllDirectories);
 
  for FileName in Files do
  begin
    Writeln(FileName);
  end;
 
  Readln;
end.
 
 