filepathutil

package
v0.74.6 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2026 License: MIT Imports: 5 Imported by: 7

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ChangeStripExtension added in v0.64.5

func ChangeStripExtension(fp, newext string) string

func CurLeafDir

func CurLeafDir() (string, error)

CurLeafDir returns the leaf dir of a nested directory.

func FilepathLeaf

func FilepathLeaf(s string) string

FilepathLeaf returns the last element of a path.

func FilterFilepaths

func FilterFilepaths(paths []string, inclExists, inclNotExists, inclFiles, inclDirs bool) []string

FilterFilepaths filters a slice of filepaths using various options.

func IsAbsAny added in v0.74.6

func IsAbsAny(path string) bool

IsAbsAny returns true if the path is absolute on any platform. Unlike filepath.IsAbs, this function recognizes both Unix-style paths (starting with /) and Windows-style paths (starting with drive letter like C:\) regardless of the current operating system.

This is useful when handling paths that may come from different platforms, such as in cross-platform tools, SARIF output, or configuration files.

Examples:

IsAbsAny("/Users/test/file.txt")     // true (Unix absolute)
IsAbsAny("C:\\Users\\test\\file.txt") // true (Windows absolute)
IsAbsAny("C:/Users/test/file.txt")    // true (Windows with forward slashes)
IsAbsAny("relative/path.txt")         // false
IsAbsAny("./relative/path.txt")       // false

func NormalizePath added in v0.74.2

func NormalizePath(p string) string

NormalizePath converts a file path to use forward slashes for consistent cross-platform comparison. This is useful when comparing paths that may come from different sources (e.g., Unix-style paths in config files on Windows).

The path is first cleaned using filepath.Clean, then all backslashes are converted to forward slashes.

func Trim

func Trim(file string) string

Trim trims the provided filepath using `os.PathSeparator`

func TrimExt added in v0.40.9

func TrimExt(path string) string

TrimExt removes the extension, including a trailing period.

func TrimLeft

func TrimLeft(file string) string

TrimLeft left trims the provided filepath using `os.PathSeparator`

func TrimRight

func TrimRight(file string) string

TrimRight right trims the provided filepath using `os.PathSeparator`

func UserToAbsolute

func UserToAbsolute(file string) (string, error)

UserToAbsolute converts ~ directories to absolute directories in filepaths. This is useful because ~ cannot be resolved by ioutil.ReadFile().

Types

This section is empty.

Jump to

Keyboard shortcuts

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