Documentation ¶
Overview ¶
Package osutil implements some OS utility functions.
Package osutil implements some OS utility functions.
Index ¶
- Constants
- func AbsFilepath(path string) (string, error)
- func CreateFileWithLines(filename string, lines []string, lineSuffix string, useBuffer bool) error
- func EmptyAll(name string) error
- func EnvExists(fields ...string) (missing []string, haveAll bool)
- func EnvFiltered(rx *regexp.Regexp) map[string]string
- func Exists(name string) (bool, error)
- func FileModAge(name string) (time.Duration, error)
- func FileModAgeFromInfo(fi os.FileInfo) time.Duration
- func FinfosToFilepaths(dir string, fis []os.FileInfo) []string
- func GetFileInfo(path string) (os.FileInfo, error)
- func IsDir(name string) (bool, error)
- func IsFile(name string, sizeGtZero bool) (bool, error)
- func MustUserHomeDir(subdirs ...string) string
- func ReadDirMore(dir string, rx *regexp.Regexp, inclDirs, inclFiles, inclEmptyFiles bool) ([]os.DirEntry, error)
- func ReadDirRxSubmatch(dir string, rx *regexp.Regexp, subMatchIdx uint, ...) (map[string][]os.DirEntry, error)
- func ReadDirRxSubmatchCaptureGreatest(dir string, rx *regexp.Regexp, subMatchIdx uint, ...) (string, error)
- func ReadDirRxSubmatchCaptures(dir string, rx *regexp.Regexp, subMatchIdx uint, ...) ([]string, error)
- func ReadDirRxSubmatchEntriesGreatest(dir string, rx *regexp.Regexp, subMatchIdx uint, ...) ([]os.DirEntry, error)
- func ReadSubdirMax(dir string, rx *regexp.Regexp) (os.DirEntry, error)
- func ReadSubdirMin(dir string, rx *regexp.Regexp) (os.DirEntry, error)
- func UserGoSrcDir() (string, error)
- type DirEntries
- type DirEntriesMore
- type DirEntryMore
- type EnvVar
- type FileInfoMore
Constants ¶
const ( ColDir = "dir" ColName = "name" ColPath = "path" ColSize = "size" )
Variables ¶
This section is empty.
Functions ¶
func AbsFilepath ¶
AbsFilepath returns an absolute filepath, using the user's current / home directory if indicated in the filepath string.
func CreateFileWithLines ¶
CreateFileWithLines creates a file and writes lines to it. It will optionally add a `lineSuffix` (e.g. `"\n"`) and use `bufio`.
func EmptyAll ¶
EmptyAll will delete all contents of a directory, leaving the provided directory. This is different from os.Remove which also removes the directory provided.
func EnvFiltered ¶
EnvFiltered returns a map[string]string of environment variables that match a regular expression.
func FileModAge ¶
FileModAge returns a time.Duration representing the age of the named file from FileInfo.ModTime().
func FileModAgeFromInfo ¶
FileModAgeFromInfo returns the file last modification age as a time.Duration.
func FinfosToFilepaths ¶
FinfosToFilepaths returns a slice of string from a directory and sli=ce of `os.FileInfo`.
func GetFileInfo ¶
GetFileInfo returns an os.FileInfo from a filepath.
func IsFile ¶ added in v0.27.2
IsFile verifies a path exists and is a file. It will optionally check if a file is not empty. An os file not exists check can be done with os.IsNotExist(err) which acts on error from os.Stat().
func MustUserHomeDir ¶ added in v0.31.1
func ReadDirMore ¶ added in v0.27.1
func ReadDirRxSubmatch ¶ added in v0.27.3
func ReadDirRxSubmatch(dir string, rx *regexp.Regexp, subMatchIdx uint, inclDirs, inclFiles, inclEmptyFiles bool) (map[string][]os.DirEntry, error)
ReadDirRxSubmatch takes a directory, regular expression and boolean to indicate whether to include zero size files and returns the greatest of a single match in the regular expression.
func ReadDirRxSubmatchCaptureGreatest ¶ added in v0.27.4
func ReadDirRxSubmatchCaptureGreatest(dir string, rx *regexp.Regexp, subMatchIdx uint, inclDirs, inclFiles, inclEmptyFiles bool) (string, error)
ReadDirRxSubmatchCaptureGreatest takes a directory, regular expression and returns the greatest of a single submatch in the regular expression.
func ReadDirRxSubmatchCaptures ¶ added in v0.27.4
func ReadDirRxSubmatchCaptures(dir string, rx *regexp.Regexp, subMatchIdx uint, inclDirs, inclFiles, inclEmptyFiles bool) ([]string, error)
ReadDirRxSubmatchCaptures takes a directory, regular expression and returns the greatest of captures from the regular expression.
func ReadDirRxSubmatchEntriesGreatest ¶ added in v0.27.4
func ReadSubdirMax ¶ added in v0.27.0
func ReadSubdirMin ¶ added in v0.27.0
func UserGoSrcDir ¶ added in v0.0.2
Types ¶
type DirEntries ¶ added in v0.30.1
func (DirEntries) Infos ¶ added in v0.30.1
func (entries DirEntries) Infos() ([]os.FileInfo, error)
Infos returns a `[]os.FileInfo` slice.
func (DirEntries) Len ¶ added in v0.30.1
func (entries DirEntries) Len() int
func (DirEntries) Less ¶ added in v0.30.1
func (entries DirEntries) Less(i, j int) bool
func (DirEntries) Names ¶ added in v0.30.1
func (entries DirEntries) Names(dir string, sortNames bool) []string
Names returns a slice of entry names. It can optionally add the directory path and sort the values.
func (DirEntries) Sort ¶ added in v0.30.1
func (entries DirEntries) Sort()
func (DirEntries) Swap ¶ added in v0.30.1
func (entries DirEntries) Swap(i, j int)
type DirEntriesMore ¶ added in v0.30.14
type DirEntriesMore []DirEntryMore
func ReadDirFiles ¶ added in v0.30.14
func ReadDirFiles(dir string, inclDirs, inclFiles, recursive bool) (DirEntriesMore, error)
type DirEntryMore ¶ added in v0.30.14
type FileInfoMore ¶
FileInfoMore provides a struct hold FileInfo with additional information.
func NewFileInfoMoreFromPath ¶
func NewFileInfoMoreFromPath(path string) (FileInfoMore, error)
NewFileInfoMoreFromPath returns a FileInfoMore struct populatig both FileInfo and ModAge (last modification time).