pathutil

package
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 25, 2026 License: MIT Imports: 13 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoHome = errors.New("home directory cannot be determined")

Error of a home directory lookup that found nothing

Functions

func CleanKeepDotDot

func CleanKeepDotDot(p string) string

Path with repeated separators and dot elements dropped and every dot-dot kept, so it still names the file the system opens when a dot-dot climbs out of a symlinked directory; a dot when nothing is left

func DirKeepDotDot

func DirKeepDotDot(p string) string

CleanKeepDotDot form of p without its final element, a dot-dot one included, so it is the directory the system walks through to reach that element; the bare anchor or a dot when p has no element

func ExpandEnv

func ExpandEnv(s string) string

Text with $name and ${name} references, and on Windows also %name%, $$, %% and literal 'quoted' spans, replaced from the environment, references to unset variables left as written

func ExpandUser

func ExpandUser(p string) string

Path with a leading ~ or ~name replaced by that user's home directory, unchanged when that home cannot be found

func ExpandUserKeepDotDot

func ExpandUserKeepDotDot(p string) (string, error)

CleanKeepDotDot form of p with a leading ~ or ~name replaced by that user's home directory, so a dot-dot after a symlink still names what the system opens; an error wrapping ErrNoHome when that home cannot be found

func ExpandUserPath

func ExpandUserPath(p string) (string, error)

Cleaned path with a leading ~ or ~name replaced by that user's home directory, an error wrapping ErrNoHome when that home cannot be found

func FileURL

func FileURL(p string) (string, error)

File URL of an absolute path with every byte but unreserved characters and separators percent-encoded, file:///C:/x for a Windows drive and file://host/share/x for a share, the \\?\ long-path forms of both included

func FoldCase

func FoldCase(p string) string

Comparison key of a path for a host whose file names ignore case: lower case with backslash separators on Windows, the path itself elsewhere

func FromFileURL

func FromFileURL(rawURL string) (string, error)

Native path a file URL names, failing for another scheme, an encoded separator, or another host except on Windows where a host names a share

func Glob

func Glob(root, pattern string) ([]string, error)

Paths below root matching a relative pattern of shell wildcard elements, ** standing for any depth of directories without entering symlinked ones and a trailing separator for directories only, in directory order

func Home

func Home() (string, error)

Cleaned home directory of the current user, from the environment and else from the account database

func IsMissing

func IsMissing(err error) bool

Whether err says a path is not there: not found, below a non-directory, behind a symlink loop or not a valid name

func Join

func Join(base string, elem ...string) string

Elements joined like filepath.Join, except that an absolute element replaces everything before it

func JoinKeepDotDot

func JoinKeepDotDot(base string, elem ...string) string

Elements joined as Join joins them, an absolute element replacing everything before it, with the result in CleanKeepDotDot form instead of cleaned; empty when every element is empty

func Name

func Name(p string) string

Final element of the cleaned path, empty for an empty, dot or root path

func NameKeepDotDot

func NameKeepDotDot(p string) string

Final element of the CleanKeepDotDot form of p, a dot-dot one included, empty for a bare anchor or a path with no element

func Parents

func Parents(p string) []string

Ancestors of the cleaned path from its parent up to its root, or up to a dot for a relative path

func Parts

func Parts(p string) (anchor string, elems []string)

Anchor of a path, its volume and root separator, and its elements with empty and dot elements dropped and dot-dot kept

func RelativeTo

func RelativeTo(p, root string) (string, bool)

Path of p below root with slash separators, a dot for root itself, false unless p is root or inside it once both are cleaned; case is ignored on Windows

func RelativeToKeepDotDot

func RelativeToKeepDotDot(p, root string) (string, bool)

Elements of p after those of root joined with slashes, both taken in CleanKeepDotDot form so a dot-dot is matched as an element and the result names the same file below root; a dot for root itself, false unless the anchor and elements of root begin p; case is ignored on Windows

func Resolve

func Resolve(p string) (string, error)

Absolute path with every symlink resolved as far as the path exists, the missing tail and any symlink loop kept as written

func ResolveExisting

func ResolveExisting(p string) (string, error)

Absolute path with every symlink resolved, failing when any part of it is missing, not a directory where one is needed or a symlink loop

func ResolveLink(dir, target string) (string, error)

Where a symlink in dir holding the text target leads, resolved as Resolve resolves a path, a relative target walked from dir the way the system follows it instead of being cleaned against dir first

func SlashRel

func SlashRel(base, target string) (string, error)

Slash separated path that leads from base to target lexically on any host, failing when only one of them is absolute or base climbs out of reach

func SplitExt

func SplitExt(p string) (root, ext string)

Path as written split before the extension of its final element, the extension found the way Suffix finds it

func StatIfExists

func StatIfExists(p string) (fs.FileInfo, error)

Followed stat of p, a nil info and nil error when IsMissing reads its failure as a missing path or p holds a NUL byte

func Stem

func Stem(p string) string

Final element without its Suffix

func Suffix

func Suffix(p string) string

Extension of the final element from its last dot, empty when that dot is one of the leading dots of a name such as .bashrc

func TempDir

func TempDir() (string, error)

First of the TempDirCandidates in which this process can create, write and remove a file, made absolute

func TempDirCandidates

func TempDirCandidates() []string

Directories a temporary directory is chosen from, in order: TMPDIR, TEMP and TMP when set, the platform's usual places, then the working directory

func WindowsBase

func WindowsBase(p string) string

Final element of a Windows path on any host after trailing separators, a dot for an empty path and a backslash for a bare anchor, the way filepath.Base treats Windows paths

func WindowsClean

func WindowsClean(p string) string

Windows path cleaned on any host: backslash separators, empty and dot elements dropped, dot-dot folded below the anchor, a dot for nothing

func WindowsDir

func WindowsDir(p string) string

Windows path without its final element on any host, cleaned, a dot when no directory is left and the share itself for a share root, the way filepath.Dir treats Windows paths

func WindowsFoldCase

func WindowsFoldCase(p string) string

Comparison key of a Windows path on any host, lower case with backslash separators

func WindowsIsAbs

func WindowsIsAbs(p string) bool

Whether a Windows path is absolute on any host: a drive letter followed by a separator, or a leading double separator

func WindowsJoin

func WindowsJoin(base string, elem ...string) string

Elements joined and cleaned under Windows rules on any host: a rooted element restarts the path on the current drive, another drive restarts it, empty for nothing but empty elements

func WindowsSplitDrive

func WindowsSplitDrive(p string) (drive, rest string)

Drive letter or UNC share of a Windows path on any host and everything after it

func WindowsSplitRoot

func WindowsSplitRoot(p string) (drive, root, rest string)

Drive letter or UNC share, root separator and the rest of a Windows path on any host, the three concatenating back to p

func WithSuffix

func WithSuffix(p, suffix string) (string, error)

Cleaned path with the Suffix of its final element replaced by suffix, which is empty or starts with a dot and holds no separator, so that any Suffix result fits

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL