fileutil

package
v0.85.0 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CopyEmbedDir added in v0.16.0

func CopyEmbedDir(fs embed.FS, src, dst string) error

CopyEmbedDir copies an embedded directory to the local file system.

func CopyToTempFile

func CopyToTempFile(r io.Reader, name, ext string) (string, int64, error)

CopyToTempFile pipes a reader to a temporary file. The caller must delete the temporary file when it's no longer needed.

func EnsureTrailingDelim added in v0.85.0

func EnsureTrailingDelim(p string, delim byte) string

EnsureTrailingDelim returns p with a trailing delimiter. If p already ends with delim, it is returned unchanged.

func ExpandHome added in v0.19.0

func ExpandHome(path string) (string, error)

func ForceRemoveFiles added in v0.19.0

func ForceRemoveFiles(paths []string)

ForceRemoveFiles deletes multiple files ignores path errors if any

func FullExt

func FullExt(path string) string

FullExt returns all of path's extensions. For example, for "foo.csv.zip" it returns ".csv.zip", not just ".zip" as filepath.Ext from the standard library does.

func GlobPrefix added in v0.85.0

func GlobPrefix(p string) (prefix string)

GlobPrefix returns the literal (non-glob) prefix of p.

It returns the substring of p up to (but not including) the first unescaped glob meta character: '*', '?', '[', or '{'. Escaped meta characters (preceded by '\') are treated as literals. If p contains no unescaped meta characters, p is returned unchanged.

Examples:

GlobPrefix("a/b/c/*.txt")    → "a/b/c/"
GlobPrefix("a/b/c/file*.go") → "a/b/c/file"
GlobPrefix("meta*/**")       → "meta"

func IsDoubleStarGlob added in v0.85.0

func IsDoubleStarGlob(path string) bool

IsDoubleStarGlob reports whether path contains an unescaped "**".

A backslash '\' escapes the following character, so "\**" does not count as a double-star glob.

func IsGlob added in v0.19.0

func IsGlob(path string) bool

IsGlob reports whether path contains any unescaped glob meta characters: '*', '?', '[', or '{'. A backslash '\' escapes the following character.

func OpenTempFileInDir added in v0.21.0

func OpenTempFileInDir(dir, filePath string) (*os.File, error)

OpenTempFileInDir opens a temp file in given dir If dir doesn't exist it creates full dir path (recursively if required)

func PathLevel added in v0.85.0

func PathLevel(p string, delim byte) int

PathLevel returns the number of path components in p separated by delim. Empty components (from repeated delimiters) are ignored. Leading and trailing delimiters do not create extra components.

Examples (delim = '/'):

"a"          → 1
"a/b"        → 2
"a/b/c"      → 3
"a/b/c/"     → 3
"a/b//c"     → 3
"/a/b/c/"    → 3

func PrefixUntilLevel added in v0.85.0

func PrefixUntilLevel(p string, level int, delim byte) string

PrefixUntilLevel returns the prefix of p that contains the first `level` path components separated by delim. Empty components (from repeated delimiters) are ignored.

If p has fewer than `level` components, p is returned unchanged.

Examples (delim = '/'):

"a/b/c/d.txt", level=1 → "a/"
"a/b/c/d.txt", level=2 → "a/b/"
"a/b/c/d.txt", level=3 → "a/b/c/"
"a/b/c/d.txt", level=4 → "a/b/c/d.txt"

"a/b//c/d.txt", level=3 → "a/b//c/"
"/a/b/c", level=2 → "/a/b/"

func ResolveLocalPath added in v0.32.0

func ResolveLocalPath(path, root string, allowHostAccess bool) (string, error)

func ShellEscape added in v0.84.0

func ShellEscape(s string) string

ShellEscape returns s wrapped in single quotes if it contains characters that are special in POSIX shells (spaces, globs, etc.). Safe strings are returned unchanged.

func Stem added in v0.16.0

func Stem(path string) string

Stem returns the file name after removing directory and all extensions. Uses FullExt to strip extensions.

Types

This section is empty.

Jump to

Keyboard shortcuts

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