::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:
class Io.Directory.Public  public Gilda:  Perform file system operations on directories.

  type Directory.Id   is      &Handle for listing a directory
    - Id = 0   word           :Hide the implementation of directory.

  type Tame.Tree  is          &Recursively return subdirectories and file names.
      Dir      Directory.Id,  &Current directory being sequenced.
      Path     string,        &Current directory path name.  Ends with "/".
      Pending  Queue..string  :Pending directories.

import Io.Path.Public,
       Stack(Bit)
:
:...............................................................................


:::::::::::::::::::::::::::  io/directory/Io.Directory  ::::::::::::::::::::::::
:
method CHANGE.DIRECTORY:  Change the current working directory.

 entry Path   string    :Target OS path.

  exit Code   byte      :0 - Okay; else error.
:
:...............................................................................
:
method IN.NEW:  Create a directory and go into it.

 entry Path     string     :The OS path name for the directory.

  exit Status   byte       :0 - created and in;
                           :1 - exists and in;
                           :2 - Create failed.
                           :3 - Created, but can't go in.
:
:...............................................................................
:
method COPY.DIRECTORY:  Recursively duplicate a directory.

 entry From     string,  &Source directory path (tame, os path, forward slash).
       To       string,  &New target path (tame, optional trailing "/").
       All = 0  Bit      :1 - Overwrite read-only files; 0 - Fail if read-only.
:
:...............................................................................
:
method COPY.MOVE.DIRECTORY:  Recursively duplicate a directory.

 entry From   string,        &Source directory path (tame).
       To     string,        &New target path (tame, optional trailing "/").
       Move = 0  Bit         :0 - Copy; On - Move
:
:...............................................................................
:
method DELETE.DIRECTORY:  Erase a directory and subdirectories.

 entry Root       string       :Relative tame directory path to kill
                               :   (forward slash; trailing slash optional).

  exit Miss  = 0  Bit          :0 - The directory was deleted okay.
                               :1 - There were unremovable subdirectories.
                               :    The directory was partially deleted.

 entry Force = 0  Bit          :Erase read only files if permitted.
:
:...............................................................................
:
method MOVE.DIRECTORY:  Rename a  directory.  Slack dependent???

 entry From     string,          &O.S. path name of the single item to move.
       To       string
:
:...............................................................................



:::::::::::::::::::::::::  io/directory/id/Directory.Id  :::::::::::::::::::::::
:
method OPEN..Directory.Id:  Initiate an iterator to access a directories contents.

  exit Directory.Id         : An Id used to reference the directory.
                            :   0 if the directory does not exist or
                            :   if out of memory.

 entry Path  string         : The Os path name for the directory (no wildcards).
:
:...............................................................................
:
method CLOSE..Directory.Id:  Release a directory scan.

change Directory.Id         :The directory id returned from Open.Directory.
:
:...............................................................................
:
method DRAIN..Directory.Id:  Release an open directory.

change Directory.Id         :The directory id returned from Open.Directory.
:
:...............................................................................
:
method NEXT..Directory.Id:  Returns the name of the next element in a directory.

change Directory.Id         :The directory id returned from Open.Directory.

  exit Next   string        :The name of the next entry.  If the entry
                            :    is a directory, it will _NOT_ end in "/".
                            :    Null when no more directory entries.
:
:...............................................................................
:
method NEXT.ATTRIBUTE..Directory.Id:  Returns the name of the next element in a directory.

change Directory.Id         :The directory id returned from Open.Directory.

  exit Next   string,       &The name of the next entry.  If the entry
                            &    is a directory, it will _NOT_ end in "/".
                            &    Null when no more directory entries.
       Attribute
:
:...............................................................................
:
sequence LIST.DIRECTORY:  Name of elements in a directory.

 entry Path   string        : The Os path name for the directory (no wildcards).

  exit Name   string        :The name of the next entry.  If the entry
                            :    is a directory, it will _NOT_ end in "/".
:
:...............................................................................
:
method CLOSE..List.Directory  pure:  Call when done listing directory elements.

change ~List.Directory      :List.Directory iterator
:
:...............................................................................



:::::::::::::::::::::::::::  io/directory/tame/Tame.Tree  ::::::::::::::::::::::
:
method OPEN..Tame.Tree:  Initialize a recursive bredth first directory scan.

change Tame.Tree            : In - clean iterator;
                            :Out - Recursive directory iterator.
                            :      $Path = "" if directory not found.

 entry Root   string        :Directory (relative; tame; os path;
                            :   any slash; trailing slash optional).
:
:...............................................................................
:
method NEXT..Tame.Tree:  Recursively return the next directory or file.

change Tame.Tree             :In - An open recursive directory id.
                             :Out - If $Path = "" then inaccessible or
                             :      out of memory.

  exit Component  string     :File name or directory path with trailing /.
                             :Null if done.

 entry Depth = 0  Bit        :Depth first if set; else bredth.
:
:...............................................................................
:
method CLOSE..Tame.Tree:  Closes a recursive directory iteration before completion.

change Tame.Tree             :An open directory id.
:
:...............................................................................
:
method DRAIN..Tame.Tree  pure:  Closes a recursive directory iteration before completion.

change Tame.Tree             :A possibly open directory id.
:
:...............................................................................
:
sequence TAME.TREE:  Bredth first search of a directory tree.

 entry Root    string,      &Directory (relative; tame; os path;
                            &   any slash; trailing slash optional).
       Depth = 0  Bit       :Depth first if set; else bredth.

  exit Component  string    :File name or subdirectory path with trailing '/'.
                            :A lead space means the directory can not be accessed.
:
:...............................................................................
:
method SUPER..Tame.Tree  pure:  Tree path for the current directory.

change ~Tame.Tree           :Tame.Tree iterator

  exit Super   string       :Path of the current directory being scaned.
:
:...............................................................................
:
method PRUNE..Tame.Tree:  If the sequence is active, Close it.

change ~Tame.Tree           :Tame.Tree iterator
:
:...............................................................................
:
method TERMINATE..Tame.Tree:  Release open directories.

change ~Tame.Tree           :Tame.Tree iterator
:
:...............................................................................



:::::::::::::::::::::::::::  io/directory/wild/Wild.Tree  ::::::::::::::::::::::

method OPEN.TREE:  Begin listing directory trees for selected files.

 entry Dual   string    :<root directory>[/<tail>]  (wild)
:
:...............................................................................
:
method CLOSE.TREE:  Terminate a directory scan prematurely.
:
: If the scan completes you do not need to call this method.
:...............................................................................
:
method NEXT.TREE:  Get the next directory of file in a tree.

  exit Os     string      :OS path name (no wildcards) or "" (Element = None).
                          :   Full path name if above the current directory or
                          :   relative to the current directory.
                          :   Forward slashes; trailing slash if a directory.
:
:...............................................................................
:
sequence WILD.TREE

 entry Cross    string    :<root directory>[/<tail>]  (wild)

  exit Os       string      :OS path name (no wildcards).
                            :   Full path name if above the current directory or
                            :   relative to the current directory.
                            :   Forward slashes; trailing slash if a directory.
:
:...............................................................................
:
method CLOSE..Wild.Tree

change ~Wild.Tree
:
:...............................................................................


end