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). 


use System.IO.File;
 
class Test {
  function : Main(args : String[]) ~ Nil {
    if(args->Size() = 2) {
      DescendDir(args[0], args[1]);
    };
  }
 
  function : DescendDir(path : String, pattern : String) ~ Nil {
    files := Directory->List(path);
    each(i : files) {
      file := files[i];
      if(<>file->StartsWith('.')) {
        dir_path := String->New(path);
        dir_path += '/';
        dir_path += file;
 
        if(Directory->Exists(dir_path)) {
          DescendDir(dir_path, pattern);
        }
        else if(File->Exists(dir_path) & dir_path->EndsWith(pattern)) {
          dir_path->PrintLine();
        };
      };
    };
  }
}