====================================================================
FileName examples
====================================================================

The FileName domain provides an interface to the computer's file
system.  Functions are provided to manipulate file names and to test
properties of files.
 
The simplest way to use file names in the Axiom interpreter is to rely
on conversion to and from strings.  The syntax of these strings
depends on the operating system.

  fn: FileName
                       Type: Void

On Linux, this is a proper file syntax:

  fn := "fname.input"
    "fname.input"
                       Type: FileName

Although it is very convenient to be able to use string notation
for file names in the interpreter, it is desirable to have a portable
way of creating and manipulating file names from within programs.

A measure of portability is obtained by considering a file name to
consist of three parts: the directory, the name, and the extension.

  directory fn
    ""
                      Type: String

  name fn
    "fname"
                      Type: String

  extension fn
    "input"
                      Type: String

The meaning of these three parts depends on the operating system.
For example, on CMS the file "SPADPROF INPUT M" would have directory
"M", name "SPADPROF" and extension "INPUT".
 
It is possible to create a filename from its parts.

  fn := filename("/tmp", "fname", "input") 
    "/tmp/fname.input"
                      Type: FileName

When writing programs, it is helpful to refer to directories via
variables.

  objdir := "/tmp"
    "/tmp"
                      Type: String

  fn := filename(objdir, "table", "spad")
    "/tmp/table.spad"
                      Type: FileName

If the directory or the extension is given as an empty string, then
a default is used.  On AIX, the defaults are the current directory
and no extension.

  fn := filename("", "letter", "") 
    "letter"
                      Type: FileName
 
Three tests provide information about names in the file system.

The exists? operation tests whether the named file exists.

  exists? "/etc/passwd"
    true
                      Type: Boolean

The operation readable? tells whether the named file can be read.  If
the file does not exist, then it cannot be read.

  readable? "/etc/passwd"
    true
                      Type: Boolean

  readable? "/etc/security/passwd"
    false
                      Type: Boolean

  readable? "/ect/passwd"
    false
                      Type: Boolean

Likewise, the operation writable? tells whether the named file can be
written.  If the file does not exist, the test is determined by the
properties of the directory.

  writable? "/etc/passwd"
    true
                      Type: Boolean

  writable? "/dev/null"
    true
                      Type: Boolean

  writable? "/etc/DoesNotExist"
    true
                      Type: Boolean

  writable? "/tmp/DoesNotExist"
    true
                      Type: Boolean
 
The new operation constructs the name of a new writable file.  The
argument sequence is the same as for filename, except that the name
part is actually a prefix for a constructed unique name.

The resulting file is in the specified directory with the given
extension, and the same defaults are used.

  fn := new(objdir, "xxx", "yy") 
    "/tmp/xxx1419.yy"
                      Type: FileName

See Also:
o )show FileName

