Denys Duchier
This module provides an object-oriented interface for path and OS operations on them
The module exports not only the object-oriented API for path, but also a convenient functional API built on top of the later. It should be noted however that the functional API always needs to build path objects and thus is less efficient than the OO API, though possibly occasionally more convenient.
{Path.make +VS ?P}
VS
, returns a new path object
P
. If VS
is already a path object, then it
is simply returned.
{Path.is +X ?B}
X
is a path object
Path.'class'
{Path.toString +X ?S}
{Path.toAtom +X ?A}
{Path.length +X ?N}
{Path.isAbsolute +X ?B}
{Path.isRelative +X ?B}
{Path.dirname +X ?S}
{Path.basename +X ?S}
{Path.exists +X ?B}
{Path.stat +X ?R}
{Path.isDir +X ?B}
{Path.isFile +X ?B}
{Path.size +X ?N}
{Path.mtime +X ?N}
{Path.resolve +X1 +X2 ?S}
{Path.getcwd ?S}
{Path.mkdir +X}
{Path.mkdirs +X}
{Path.isRoot +X ?B}
{Path.readdir +X ?L}
{Path.extension +X ?S}
{Path.dropExtension +X ?S}
{Path.addExtension +X +VS ?S}
{Path.maybeAddPlatform +X ?S}
{Path.rmdir +X}
Each path object P
has the following methods:
{P init(+S windows:WIN<=ISWIN exact:EXACT<=false)}
S
. WIN
indicates that it should be considered a Windows-style path: this usually
defaults to false, except on Windows where it defaults to true.
It is possible to indicate a directory by additing a terminal '/' or '\' (depending on OS). However, this slash/backslash is removed in the string output when EXACT
is set to false, which is its default value.
{P initFromRecord(+R)}
{P newFromRecord(R $)}
Path
class. It's default definition is
meth newFromRecord(R $)
{New Path initFromRecord(R)}
end
{P new(+S windows:WIN<=ISWIN exact:EXACT<=false)}
S
{P toString($)}
{P toAtom($)}
{P length($)}
{P isAbsolute($)}
{P isRelative($)}
{P dirname($)}
P
. If P
contains only a single component (i.e. P
is a plain file) then dirname returns nil
.
{P basename($)}
P
{P dirnameString($)}
P
{P basenameString($)}
P
{P exists($)}
P
exists
{P stat($)}
P
{P isDir($)}
{P isFile($)}
P
is a directory (resp. a regular file). Note that these methods only work for an actually existing file which is either an absolute path or relative to the current path (the implementation calls stat
){P isDir2($)}
{P isFile2($)}
isDir2
returns true if P
ends in a slash or backslash (depending on OS), and isFile2
returns true if P
does not end in a slash or backslash. Note that this is not a foolproof technique for checking for directories, but it works also for non-existing pathes{P size($)}
P
in bytes
{P mtime($)}
{P resolve(+P2 $)}
P2
relative to P
(if P2
is not a path, it is made
into one). In other words, P2
is attached to the end of P
. However, if P2
is an absolute path, then it returns a path object only for P2
. Note that resolve also 'appends' P2
to P
in case P
is a regular file.
{P getcwd($)}
{P mkdir}
P
{P mkdirs}
P
and its ancestor directories too
if necessary
{P rmdir}
P
{P isRoot($)}
P
is a root path
{P readdir($)}
P
. Entries for .
and ..
are
omitted. All other entries are resolved relative to P
{P extension($)}
P
, unit
if none
{P dropExtension($)}
P
, if any,
omitted
{P addExtension(+VS $)}
P
but with the
extension VS
added
{P maybeAddPlatform($)}
P
has extension so
then a new path
object is returned with the appropriate (for native functors) platform-specific
suffix added, else P
itself is returned
{P makeExecutable}
P
executable if this is meaningful on the current
platform