#line 494 "/home/travis/build/felix-lang/felix/src/packages/filesystem.fdoc"
  
  Filesystem operations parametrised by operating system.
  YET TO BE DONE.
  class FileSystem_class[os]
  {
  }
  
  Platform dependent filesystem operations for host file system.
  class FileSystem {
  if PLAT_WIN32 do
    inherit Win32FileSystem;
  else
    inherit PosixFileSystem;
  done
  
    proc unlink(f:string)
    {
      proc aux (d:string) (b:string)
      {
        if b == "." or b == ".." return;
        var f = if d == "" then b else Filename::join (d,b);
        match FileStat::filetype f with
        | #PIPE => ;
        | #STREAM => ;
        | #DIRECTORY =>
          match Directory::filesin f with
          | #None => ;
          | Some files =>
            for file in files do
              aux f file;
            done
            C_hack::ignore$ Directory::unlink_empty_dir f;
          endmatch;
        | #BLOCK => ;
        | #REGULAR => C_hack::ignore$ unlink_file f;
        | #SYMLINK => C_hack::ignore$ unlink_file f;
        | #SOCKET => ;
        | #INDETERMINATE => ;
        | #NONEXISTANT => ;
        | #NOPERMISSION => ;
        endmatch;
      }
      aux "" f;
    }
  
    proc rm (f:string) => unlink f;
  
    Find a file in a list of directories.
    fun find_in_path(x:string, path:list[string]):opt[string]=>
      match path with
      | #Empty => None[string]
      | Cons (d,t) =>
        let p =  Filename::join(d,x) in
        match FileStat::fileexists p with
        | true => Some p
        | false => find_in_path (x,t)
        endmatch
      endmatch
    ;
  
    Find all the files matching an RE2-regular expression
    in a given directory.
    NOTE: this search finds files in descendant directories too.
    The search is recursive, but the whole pathname within
    the specified directory must match the regexp.
    For example to find all *.flx files in src use:
      regfilesin("src", ".*[.]flx")
    To find the files only in the given directory, on Unix use instead
      regfilesin("src", "[^/]*[.]flx")
    to exclude files in child directories.
    fun regfilesin(dname:string, re:string): list[string] => regfilesin(dname, Re2::RE2 re);
  
    Find all the files matching a compiled RE2-regular expression.
    fun regfilesin(dname:string, re:RE2): list[string] = {
      //eprintln$ "regfilesin " + dname+ " with some kind of regexp .. ";
  
      var foundfiles = Empty[string];
      proc rfi(dname2: string) {
  
        //eprintln$ "rf() : dname2=" +dname2;
  
        if dname2 == "." or dname2 == ".." return;
  
        var newpath = if dname2 == "" then dname else Filename::join (dname,dname2);
  
        //eprintln$ "newpath = "+newpath ;
  
        var newfiles = Directory::filesin(newpath);
  
        //eprintln$ "returned from filesin" ;
  
        match newfiles with
        | #None => return;
        | Some files =>
          //eprintln$ "got files in " + newpath;
          for f in files do
            if f == "." or f == ".." do ;
            else
              //eprintln$ "Processing file " + f;
              var d = Filename::join (dname2,f);
              //eprintln$ "Relpath " + d;
              var fullpath = Filename::join (dname,d);
              //eprintln$ "fullpath " + fullpath;
              var t = FileStat::filetype fullpath;
              match t with
                | #REGULAR =>
                  //eprintln ("Regular file " + d);
                  var result = d in re;
                  if result do
  	                //eprintln$ d + " Matches";
  		              foundfiles = Cons (d, foundfiles);
                  done
                | #DIRECTORY =>
                  //eprintln ("found directory " + d);
                  rfi (d);
                | _ => ;
              endmatch;
            done
          done
        endmatch;
      }
      rfi ("");
      return rev foundfiles;
    }
  
  }