Path¶
Usage
use Path;
A file utilities library, specifically related to path operations
The Path module focuses on manipulation of the path to a file or directory. Also provided are constant values representing common idioms that may vary across operating systems (though rarely in the modern era), such as general references to a parent directory or the current directory.
Note
This module is currently under development and will expand significantly in upcoming releases. Stay tuned!
Operations which occur on the files or directories referred to by these paths
may be found in FileSystem
(for operations on the file) or IO
(for operations within the file).
-
proc
basename
(name: string): string¶ Returns the basename of the file name provided. For instance, in the name /foo/bar/baz, this function would return baz, while /foo/bar/ would yield the empty string. Note that this is different from the Unix basename function.
Arguments: name : string -- a string file name. Note that this string does not have to be a valid file name, as the file itself will not be affected.
-
const
curDir
= "."¶ Represents generally the current directory
-
proc
dirname
(name: string): string¶ Returns the parent directory of the file name provided. For instance, in the name /foo/bar/baz, this function would return /foo/bar, as would a call with /foo/bar/ as the argument.
Arguments: name : string -- a string file name. Note that this string does not have to be a valid file name, as the file itself will not be affected.
-
const
parentDir
= ".."¶ Represents generally the parent directory
-
const
pathSep
= "/"¶ Denotes the separator between a directory and its child.
-
proc
realPath
(name: string): string¶ Given a path name, attempts to determine the canonical path referenced. This resolves and removes any
curDir
andparentDir
uses present, as well as any symbolic links. Returns the resultWill halt with an error message if one is detected.
Arguments: name : string -- A path to resolve. If the path does not refer to a valid file or directory, an error will occur. Returns: A canonical version of the argument. Return type: string
-
proc
file.
realPath
(): string¶ Determines the canonical path referenced by the
file
record performing this operation. This resolves and removes anycurDir
andparentDir
uses present, as well as any symbolic links. Returns the resultWill halt with an error message if one is detected.
Returns: A canonical path to the file referenced by this file
record. If thefile
record is not valid, an error will occurReturn type: string
-
proc
splitPath
(name: string): (string, string)¶ Split name into a tuple that is equivalent to (
dirname
,basename
). The second part of the tuple will never contain a slash. Examples:splitPath("foo/bar") will yield ("foo", "bar")
splitPath("bar") will yield ("", "bar")
splitPath("foo/") will yield ("foo", "")
splitPath("") will yield ("", "")
splitPath("/") will yield ("/", "")
With the exception of a path of the empty string or just "/", the original path can be recreated from this function's returned parts by joining them with the path separator character:
dirname + "/" + basename
Arguments: name : string -- path to be split