For the latest stable version, please use Emilua API 0.10! |
filesystem.path
Objects of this class abstract path-manipulation algorithms for the host operating system.
Methods from this class are purely computational and never trigger any syscall. They only operate on the in-memory representation of a path. They do not perform any operation on the filesytem. They do not initiate any I/O request.
Paths are immutable. Any operation on a path will return a new path with the result.
Functions
new() → path
new() (1)
new(str) (2)
1 | Default constructor. |
2 | Create a path from an UTF-8 encoded string (in the host system format). |
iterator(self) → function
Returns an iterator to the path components (as strings). The iteration order follows:
-
The root name, if any.
-
The root directory, if any.
-
The sequence of file names, omitting directory separators.
-
If there is a directory separator after the last file name in the path, the last element is an empty element.
make_preferred(self) → path
Returns a new path where all directory separators are converted to the preferred directory separator.
On Windows, where "\" is the preferred separator, the path "foo/bar"
will be converted to "foo\bar" .
|
replace_filename(self, replacement: string|path) → path
Returns a new path where the filename component is replaced.
replace_extension(self[, replacement: string|path]) → path
Returns a new path where the extension is replaced (or removed on nil
).
Metamethods
-
__tostring()
: Encodes the native representation as UTF-8 and returns it. -
__eq()
: Compares two paths lexicographically. -
__lt()
: Compares two paths lexicographically. -
__le()
: Compares two paths lexicographically. -
__div()
: Concatenates two paths with a directory separator. -
__concat()
: Concatenates the underlying native representation of the paths (i.e. no additional directory separators are introduced). This operation may not be portable between operating systems.