osutil

package
v0.29.1 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2021 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package osutil implements some OS utility functions.

Package osutil implements some OS utility functions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AbsFilepath

func AbsFilepath(path string) (string, error)

AbsFilepath returns an absolute filepath, using the user's current / home directory if indicated in the filepath string.

func CreateFileWithLines

func CreateFileWithLines(filename string, lines []string, lineSuffix string, useBuffer bool) error

CreateFileWithLines creates a file and writes lines to it. It will optionally add a `lineSuffix` (e.g. `"\n"`) and use `bufio`.

func EmptyAll

func EmptyAll(name string) error

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 EnvExists

func EnvExists(fields ...string) (missing []string, haveAll bool)

func EnvFiltered

func EnvFiltered(rx *regexp.Regexp) map[string]string

EnvFiltered returns a map[string]string of environment variables that match a regular expression.

func Exists

func Exists(name string) (bool, error)

Exists checks whether the named filepath exists or not for a file or directory.

func FileModAge

func FileModAge(name string) (time.Duration, error)

FileModAge returns a time.Duration representing the age of the named file from FileInfo.ModTime().

func FileModAgeFromInfo

func FileModAgeFromInfo(fi os.FileInfo) time.Duration

FileModAgeFromInfo returns the file last modification age as a time.Duration.

func FinfosToFilepaths

func FinfosToFilepaths(dir string, fis []os.FileInfo) []string

FinfosToFilepaths returns a slice of string from a directory and sli=ce of `os.FileInfo`.

func GetFileInfo

func GetFileInfo(path string) (os.FileInfo, error)

GetFileInfo returns an os.FileInfo from a filepath.

func IsDir added in v0.27.2

func IsDir(name string) (bool, error)

func IsFile added in v0.27.2

func IsFile(name string) (bool, error)

func IsFileWithSizeGtZero added in v0.27.2

func IsFileWithSizeGtZero(name string) (bool, error)

IsFileWithSizeGtZero verifies a path exists, is a file and is not empty, returning an error otherwise. An os file not exists check can be done with os.IsNotExist(err) which acts on error from os.Stat()

func ReadDirMore added in v0.27.1

func ReadDirMore(dir string, rx *regexp.Regexp, inclDirs, inclFiles, inclEmptyFiles bool) ([]os.DirEntry, error)

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 ReadDirRxSubmatchEntriesGreatest(dir string, rx *regexp.Regexp, subMatchIdx uint, inclDirs, inclFiles, inclEmptyFiles bool) ([]os.DirEntry, error)

func ReadSubdirMax added in v0.27.0

func ReadSubdirMax(dir string, rx *regexp.Regexp) (os.DirEntry, error)

func ReadSubdirMin added in v0.27.0

func ReadSubdirMin(dir string, rx *regexp.Regexp) (os.DirEntry, error)

func UserGoSrcDir added in v0.0.2

func UserGoSrcDir() (string, error)

Types

type DirEntrySlice added in v0.27.0

type DirEntrySlice []os.DirEntry

func (DirEntrySlice) Infos added in v0.27.3

func (slice DirEntrySlice) Infos() ([]os.FileInfo, error)

Infos returns a `[]os.FileInfo` slice.

func (DirEntrySlice) Len added in v0.27.0

func (slice DirEntrySlice) Len() int

func (DirEntrySlice) Less added in v0.27.0

func (slice DirEntrySlice) Less(i, j int) bool

func (DirEntrySlice) Names added in v0.27.1

func (slice DirEntrySlice) Names(dir string, sortNames bool) []string

func (DirEntrySlice) Sort added in v0.27.0

func (slice DirEntrySlice) Sort()

func (DirEntrySlice) Swap added in v0.27.0

func (slice DirEntrySlice) Swap(i, j int)

type EnvVar

type EnvVar struct {
	Key   string
	Value string
}

func Env

func Env() []EnvVar

type FileInfoMore

type FileInfoMore struct {
	FileInfo os.FileInfo
	ModAge   time.Duration
}

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).

Jump to

Keyboard shortcuts

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