path

Filesystem path manipulation — splitting, joining, normalizing, and comparing OS paths. Distinct from the CXPath value kind (spec/cxpath.md): this is OS-path territory. Most operations are lexical and pure; the few that touch the filesystem (`absolute`, `canonical`) are marked impure. Path logic such as normalization, relative-path computation, globbing, and containment is implemented in native primitives since it is not expressible in pure CX.

path:dirname

[$path:dirname] ($p::string) -> string — Return the directory portion of a path — everything up to (but not including) the final separator.

            [?lib 'cx-stdlib/path']
[$path:dirname "/a/b/c.txt"]
          
            '/a/b'
          

path:basename

[$path:basename] ($p::string) -> string — Return the final component of a path (the part after the last separator).

            [?lib 'cx-stdlib/path']
[$path:basename "/a/b/c.txt"]
          
            'c.txt'
          

path:extension

[$path:extension] ($p::string) -> string — Return the file extension of the final component, including the leading dot; empty if none.

            [?lib 'cx-stdlib/path']
[$path:extension "/a/b/c.txt"]
          
            '.txt'
          

path:stem

[$path:stem] ($p::string) -> string — Return the final component with its extension removed.

            [?lib 'cx-stdlib/path']
[$path:stem "/a/b/c.txt"]
          
            'c'
          

path:parent

[$path:parent] ($p::string) -> string — Return the parent directory of a path (its dirname).

            [?lib 'cx-stdlib/path']
[$path:parent "/a/b/c.txt"]
          
            '/a/b'
          

path:parts

[$path:parts] ($p::string) -> [sequence string] — Split a path into its component segments, in order.

            [?lib 'cx-stdlib/path']
[$path:parts "/a/b/c.txt"]
          
            ('a', 'b', 'c.txt')
          

path:join

[$path:join] (*$parts::string) -> string — Join path segments with the platform separator, collapsing redundant separators.

            [?lib 'cx-stdlib/path']
[$path:join "a" "b" "c"]
          
            'a/b/c'
          

path:join-seq

[$path:join-seq] ($parts::[sequence string]) -> string — Join a sequence of path segments with the platform separator (the list form of `join`).

            [?lib 'cx-stdlib/path']
[$path:join-seq ("a/", "/b/", "/c")]
          
            'a/b/c'
          

path:normalize

[$path:normalize] ($p::string) -> string — Lexically normalize a path: resolve '.' and '..' segments and collapse redundant separators, without touching the filesystem.

            [?lib 'cx-stdlib/path']
[$path:normalize "a/./b/../c"]
          
            'a/c'
          

path:absolute

[$path:absolute] ($p::string) -> string — Resolve a path to an absolute one against the current working directory (does not require the path to exist).

            [?lib 'cx-stdlib/path']
[$path:is-absolute [$path:absolute "x"]]
          
            true
          

path:relative

[$path:relative] ($from::string $to::string) -> string — Compute the relative path from `$from` to `$to`.

            [?lib 'cx-stdlib/path']
[$path:relative "/a/b" "/a/c/d"]
          
            '../c/d'
          

path:canonical

[$path:canonical] ($p::string) -> string — Resolve a path to its real absolute form on disk, following symlinks; raises CXER2600 if it does not exist.

            [?lib 'cx-stdlib/path']
[$path:canonical "/no/such/path/abcxyz-does-not-exist-12345"]
          
            cx-err:CXER2600
          

path:is-absolute

[$path:is-absolute] ($p::string) -> bool — Report whether a path is absolute (rooted).

            [?lib 'cx-stdlib/path']
[$path:is-absolute "/foo"]
          
            true
          

path:is-relative

[$path:is-relative] ($p::string) -> bool — Report whether a path is relative (not rooted).

            [?lib 'cx-stdlib/path']
[$path:is-relative "foo"]
          
            true
          

path:is-posix-style

[$path:is-posix-style] ($p::string) -> bool — Report whether a path uses POSIX (forward-slash) separators.

            [?lib 'cx-stdlib/path']
[$path:is-posix-style "/foo/bar"]
          
            true
          

path:is-windows-style

[$path:is-windows-style] ($p::string) -> bool — Report whether a path uses Windows-style separators or a drive letter.

            [?lib 'cx-stdlib/path']
[$path:is-windows-style "C:\\foo\\bar"]
          
            true
          

path:has-extension

[$path:has-extension] ($p::string) -> bool — Report whether the final component has a file extension.

            [?lib 'cx-stdlib/path']
[$path:has-extension "a.txt"]
          
            true
          

path:with-extension

[$path:with-extension] ($p::string $ext::string) -> string — Return the path with its extension replaced by $ext (a leading dot is optional).

            [?lib 'cx-stdlib/path']
[$path:with-extension "a.txt" ".md"]
          
            'a.md'
          

path:with-stem

[$path:with-stem] ($p::string $stem::string) -> string — Return the path with its stem (the name without its extension) replaced.

            [?lib 'cx-stdlib/path']
[$path:with-stem "a/b.txt" "c"]
          
            'a/c.txt'
          

path:with-name

[$path:with-name] ($p::string $name::string) -> string — Return the path with its final component replaced.

            [?lib 'cx-stdlib/path']
[$path:with-name "a/b.txt" "c.md"]
          
            'a/c.md'
          

path:append

[$path:append] ($p::string $suffix::string) -> string — Append a suffix path onto a base path, collapsing redundant separators.

            [?lib 'cx-stdlib/path']
[$path:append "a/b" "/c"]
          
            'a/b/c'
          

path:match-glob

[$path:match-glob] ($pattern::string $p::string) -> bool — Report whether a path matches a glob pattern (`*`, `?`, `[…]`, `**`); raises CXER2602 on a malformed pattern.

            [?lib 'cx-stdlib/path']
[$path:match-glob "**/*.cx" "a/b/c.cx"]
          
            true
          

path:separator

[$path:separator] () -> string — Return the platform path separator (`/` on POSIX).

            [?lib 'cx-stdlib/path']
[$path:separator]
          
            '/'
          

path:list-separator

[$path:list-separator] () -> string — Return the platform path-list separator used in variables like PATH (`:` on POSIX).

            [?lib 'cx-stdlib/path']
[$path:list-separator]
          
            ':'
          

path:is-within

[$path:is-within] ($dir::string $candidate::string) -> bool — Report whether a candidate path lies within a directory after normalization (no `..` escape).

            [?lib 'cx-stdlib/path']
[$path:is-within "/srv/www" "/srv/www/../etc/passwd"]
          
            false
          

path:safe-join

[$path:safe-join] ($base::string $untrusted::string) -> string — Join an untrusted segment onto a trusted base, raising CXER2603 if the result would escape the base.

            [?lib 'cx-stdlib/path']
[$path:safe-join "/srv/www" "a/b.txt"]
          
            '/srv/www/a/b.txt'
          

path:equals-case-insensitive

[$path:equals-case-insensitive] ($a::string $b::string) -> bool — Compare two paths for equality, ignoring case.

            [?lib 'cx-stdlib/path']
[$path:equals-case-insensitive "/A/B" "/a/b"]
          
            true