Path

Denys Duchier

provides
x-ozlib://duchier/sp/Path.ozf

Purpose

This package provides an abstraction for file and directory names and operations on them and on the corresponding file system objects.

{Path.make +S ?O}
given a string S, returns a corresponding Filename object.
{O toString($)}
returns the filename as a string
{O dirname($)}
returns the Filename object for O's directory
{O basename($)}
returns the Filename object for O's base name (i.e. last component of its path).
{O toBase($)}
to put it simply: if O doesn't end with a slash, one is added, and the corresponding Filename object is returned. This is useful for method resolve: D1 = {Path.make DIRECTORY} D2 = {D1 toBase($)} F1 = {Path.make FILENAME} F2 = {D2 resolve(F1 $)}
{O resolve(F $)}
if F is relative, prepend O's directory and return the corresponding Filename object.
{O expand($)}
if O begins with ~ or contains . or .., these are appropriately expanded and the resulting Filename object is returned.
{O stat($)}
this is just like applying OS.stat, except that when file O does not exist notFound(type:unknown size:0) is returned instead of raising an exception.
{O dirEntries($)}
returns the list of Filename objects for the files in directory O.
{O tree($)}
returns a record describing the file tree rooted at O. This record is just like what is returned by {O stat($)}, except that, in the case of a directory, the additional feature entries is present and gives a list of the file trees (in the same form) rooted at each of O's entry.
{O leaves($)}
returns a list of Filename objects for all regular files in the file tree rooted at O.
{O exists($)}
tests for the existence of file O
{O isDir($)}
tests whether O exists and is a directory.
{O isFile($)}
tests whether O exists and is a regular file.
{O size($)}
returns the size of O in bytes (0 if it doesn't exist).
{O mkdirs}
makes sure that all ancestor directories of O exists, else creates them. Thus, to ensure the existence of a directory hierarchy DIR, execute: {{{Path.make DIR} toBase($)} mkdirs}
{O rmtree}
makes sure that the file tree rooted at O does not appear on the file system. Thus, if O denotes a file, the file is deleted; if it denotes a directory, then this directory and its contents are recursively deleted.

Installation

This package can be installed using ozmake, i.e. by invoking in a shell: ./ozmake --install --package=duchier-path.pkg By default, all files of the package are installed in the user's ~/.oz directory tree. In particular, all modules are installed in the user's private cache.


Denys Duchier