(chibi pathname)

A general, non-filesystem-specific pathname library.

(path-strip-directory path)

Returns just the basename of path, with any directory removed. If path does not contain a directory separator, return the whole path. If path ends in a directory separator (i.e. path is a directory), or is empty, return the empty string.

(path-directory path)

Returns just the directory of path. If path is relative (or empty), return ".".

(path-extension path)

Returns the rightmost extension of path, not including the ".". If there is no extension, returns #f. The extension will always be non-empty and contain no "."s.

(path-strip-extension path)

Returns path with the extension, if any, removed, along with the ".".

(path-replace-extension path ext)

Returns path with the extension, if any, replaced with ext.

(path-strip-leading-parents path)

Returns path with any leading ../ removed.

(path-absolute? path)

Returns #t iff path is an absolute path, i.e. begins with "/".

(path-relative? path)

Returns #t iff path is a relative path.

(path-relative-to path dir)

Returns the suffix of path relative to the directory dir, or #f if path is not contained in dir. If the two are the same (modulo a trailing "/"), then "." is returned.

(path-resolve path dir)

Resolve path relative to the given directory. Returns path unchanged if already absolute.

(path-normalize path)

Returns a normalized version of path, with duplicate directory separators removed and "/./" and "x/../" references removed. Does not take symbolic links into account - this is meant to be abstract and applicable to paths on remote systems and in URIs. Returns path itself if path is already normalized.

(make-path . args)

Return a new string representing the path where each of args is a path component, separated with the directory separator. args may include symbols and integers, in addition to strings.