Kaba class Path ed

Represents a path in the filesystem (not necessarily pointing to an existing file).

Syntax ed

class Path

    # constructors
    func mut __init__(p: string)
    func mut __init__()

    # functions
    func absolute() -> Path
    func pure all_parents() -> Path[]
    func pure basename() -> string
    func pure basename_no_ext() -> string
    func pure canonical() -> Path
    func pure compare(p: Path) -> i32
    func pure dirname() -> string
    func pure extension() -> string
    func pure is_absolute() -> bool
    func pure is_empty() -> bool
    func pure is_relative() -> bool
    func pure parent() -> Path
    func pure relative_to(p: Path) -> Path

    # operators
    func pure __str__() -> string        # str(Path) -> string
    func pure __repr__() -> string       # repr(Path) -> string
    func pure __bool__() -> bool         # bool(Path) -> bool
    func mut __assign__(b: Path)         # Path = Path
    func pure __eq__(b: Path) -> bool    # Path == Path -> bool
    func pure __neq__(b: Path) -> bool   # Path __neq__ Path -> bool
    func pure __lt__(b: Path) -> bool    # Path < Path -> bool
    func pure __gt__(b: Path) -> bool    # Path > Path -> bool
    func pure __bitor__(b: Path) -> Path # Path | Path -> Path
    func pure __bitor__(b: string) -> Path # Path | string -> Path
    func pure __contains__(b: Path) -> bool # Path in Path -> bool

    # constants
    let EMPTY: Path

Functions ed

func absolute() -> Path
Find the absolute path for a relative one.

func pure all_parents() -> Path[]
Creates a list of all parent directories.

func pure basename() -> string
Get the basename of a path as a string ('a/b/c.txt' -> 'c.txt').

func pure basename_no_ext() -> string
Get the basename without extension as a string ('a/b/c.txt' -> 'c')

func pure canonical() -> Path
Get a canonical version of a path. (removes 'a/../b')

func pure compare(p: Path) -> i32
Compare two paths alphabetically.

func pure dirname() -> string
Get the directory of a path as a string ('a/b/c.txt' -> 'a/b/').

func pure extension() -> string
Gets the extension of a filename ('a/b/c.txt' -> 'txt').

func pure is_absolute() -> bool
Check, if a path is absolute.

func pure is_empty() -> bool
Check if path is empty ('').

func pure is_relative() -> bool
Check if a path is relative, i.e. does not start with '/...' or 'X:\...'.

func pure parent() -> Path
Get the parent directory of a path.

func pure relative_to(p: Path) -> Path
Describe a path relative to another path.