Lynxer

Documentation

path

pathlib-style path manipulation and filesystem helpers.

Backend: native — stdlib/path.so, built from stdlib/path.cpp over <filesystem> and POSIX stat. Import: import("path") → global.path.*

Paths are plain strings. Functions return "", an empty list, false or -1 when the underlying operation fails.

platform() reports the POSIX host (linux, darwin, freebsd, netbsd, openbsd or dragonfly, otherwise unknown). separator() returns / and listSeparator() returns : for the supported POSIX hosts.

Construction

FunctionSignatureNotes
platform() -> strPOSIX host name
separator() -> strPath-component separator (/)
listSeparator() -> strSearch-path separator (:)
cwd / home() -> strWorking directory / home directory
absolute(str path) -> strAbsolute path without normalization or symlink resolution
resolve(str path) -> strCanonical path; missing components are allowed
expandUser(str path) -> strExpands a leading ~
join(str base, str child) -> strJoins two components
join3(str a, str b, str c) -> strJoins three components
normalize(str path) -> strCollapses . and ..; "" becomes "."

Components

FunctionSignatureNotes
name(str path) -> strFinal component
stem(str path) -> strFinal component without its suffix
suffix(str path) -> strFinal suffix, including the dot
suffixes(str path) -> listAll suffixes, e.g. [.tar, .gz]
parent(str path) -> strParent directory
anchor / root(str path) -> str/ for absolute paths, else ""
drive(str path) -> strAlways "" on POSIX
parts(str path) -> listComponents from the root
isAbsolute(str path) -> boolAbsolute-path test
match(str path, str pattern) -> boolpathlib-style glob match
relativeTo(str path, str base) -> strPath relative to base, or ""
withName(str path, str newName) -> strReplaces the final component
withSuffix(str path, str newSuffix) -> strReplaces the final suffix; "" removes it

Predicates

exists, isFile, isDir, isSymlink, isMount — (str path) -> bool. sameFile(str first, str second) -> bool compares device and inode.

Traversal

FunctionSignatureNotes
iterDir(str path) -> listDirect children as full paths, sorted
glob(str path, str pattern) -> listChildren matching a glob pattern, sorted
rglob(str path, str pattern) -> listRecursive glob, sorted

Glob patterns support *, ?, [...] and ** (which spans directories). * and ? do not cross /.

Mutation

FunctionSignatureNotes
mkdir(str path) -> boolOne directory; false if it exists
mkdirs(str path) -> boolDirectory tree (existing is fine)
rmdir / unlink(str path) -> boolRemoves an empty directory / a file
unlinkMissingOk(str path) -> boolAs unlink, treating a missing path as success
touch(str path) -> boolCreates the file and refreshes its timestamp
rename / replace(str path, str target) -> strReturns the resulting target path, or ""

Text and metadata

FunctionSignatureNotes
readText(str path) -> strUTF-8 contents, or ""
readTextEncoding(str path, str encoding) -> strReads as the named encoding: UTF-8 (including ""), ASCII, Latin-1, Windows-1252, UTF-16/32 (endianness variants), and host-supported iconv names; "" for an unknown encoding, missing file or invalid byte sequence
writeText(str path, str content) -> boolUTF-8 write
writeTextEncoding(str path, str content, str encoding) -> boolWrites in the named encoding: UTF-8 (including ""), ASCII, Latin-1, Windows-1252, UTF-16/32 (endianness variants), and host-supported iconv names; false for an unknown encoding or unrepresentable character
appendText(str path, str content) -> boolUTF-8 append
size(str path) -> intBytes, or -1
modifiedTime(str path) -> floatUnix timestamp with sub-second precision, or -1.0
asUri(str path) -> strfile:// URI of the absolute path

Example

global setup(){ import("path"); }

global main(){
    println(global.path.name("/tmp/notes.txt"));
    println(global.path.suffixes("archive.tar.gz"));
    println(global.path.rglob(".", "*.lynx"));
}

See also