std / path

path

import "std:path"

Provides Unix-style path manipulation functions. Uses forward slash (/) as the path separator. Functions are organized by allocation behavior: zero-alloc functions return views into input strings, allocating functions use heap allocation.

View source on Codeberg →

Path Splitting (Zero-Alloc)

#
func Split(path string) (string, string)

Splits a path into its directory and file components at the last slash. Returns a view into the original string with no allocation.

#
func Dir(path string) string

Returns the directory component of a path, that is, everything up to and including the final slash. Returns a view into the original string with no allocation.

#
func Base(path string) string

Returns the last element of a path, that is, everything after the final slash. Returns a view into the original string with no allocation.

#
func Ext(path string) string

Returns the file extension of a path, including the leading dot. Returns an empty string if there is no extension. Returns a view into the original string with no allocation.

Path Testing (Zero-Alloc)

#
func IsAbs(path string) bool

Reports whether the path is absolute, that is, whether it begins with a forward slash.

Path Cleaning (Allocating)

#
func Clean(path string) string

Returns the shortest path name equivalent to path by lexical processing. Eliminates multiple slashes, . elements, and .. elements. Allocates a new string for the result.

Path Construction (Allocating)

#
func Join(parts []string) string

Joins any number of path elements into a single path, separating them with slashes. Empty elements are ignored. The result is cleaned as if by Clean. Allocates a new string for the result.

Pattern Matching (Zero-Alloc)

#
func Match(pattern, name string) bool

Reports whether name matches the shell file name pattern. Supports * (any sequence of non-separator characters) and ? (any single non-separator character). Performs no allocation.