file

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2022 License: GPL-3.0 Imports: 6 Imported by: 2

README

Go Reference Go Report Card REUSE status

Go Utilities: file

Go package with utilities that support the work with files.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckMkdir

func CheckMkdir(path string, perm os.FileMode) error

CheckMkdir checks if a directory exists. If it doesn't exist, it's being created

func Copy

func Copy(srcFn, dstFn string) error

Copy copies srcFn to dstFn. Prequisite is, that srcFn and (if existing) dstFn are regular files (i.e. no devices etc.). In case both files are the same, nothing is done. In case, dstFn is already existing it is overwritten.

func Exists

func Exists(path string) (bool, error)

Exists returns true if path exists, otherwise false

func Find

func Find(roots []Info, filter func(Info, ValidPropagate) (bool, ValidPropagate), numWorkers int) (files *[]*Info)

Find traverses directory trees to find files that fulfill a certain filter condition. It starts at a list of root directories. The condition must be implemented in a function, which is passed to Find as a parameter. This condition returns two boolean value. The first one determines if a certain entry is valid (i.e. fulfills the actual filter condition), the second determines (only in case of a directory) if the filter result (i.e. the first boolean) shall be propagated to the entries of the directory. numWorkers is the number of concurrent Go routines that Find uses. Find returns the absolute paths of the files and directories that fulfill the filter condition as string array. This function is inspired by the Concurrent Directory Traversal from the book "The Go Programming Language" by Alan A. A. Donovan & Brian W. Kernighan. See: https://github.com/adonovan/gopl.io/blob/master/ch8/du4/main.go

func GlobOr

func GlobOr(patterns []string) (matches []string, err error)

GlobOr execute filepath.Glob on a list of patterns. The result is a list of files that match at least one of the patterns in the list. GlobOr returns an error if at least one of the calls of filepath.Glob returned an error

func IsDir

func IsDir(path string) (bool, error)

IsDir returns true is path exists and is a directory

func IsEmpty

func IsEmpty(path string) (bool, error)

IsEmpty returns true if file or directory is empty, otherwise false

func MkdirAll

func MkdirAll(path string, perm os.FileMode) error

MkdirAll creates a directory named path, along with any necessary parents. In this regard, it behaves like the standard os.MkdirAll. In contrast to this, it doesn't complain if path already exists.

func RemoveEmpty

func RemoveEmpty(f string) error

RemoveEmpty removes a file or directory if it is empty. If it is not empty, RemoveEmpty returns an error

func RenameAll

func RenameAll(pattern string, path string) error

RenameAll moves all files that match pattern to path

Types

type Info

type Info interface {
	os.FileInfo
	Path() string // get complete file name
}

Info extends the standard interface os.FileInfo

func ExistsInfo

func ExistsInfo(path string) (bool, Info, error)

ExistsInfo returns true if path exists, otherwise false. In addition to Exists it also return file.Info

func Stat

func Stat(path string) (Info, error)

Stat returns info about the file whose path is passed as parameter. In this regard, it is simlar to the standard function os.Stat. Different from it, FileStat returns file info of type FileInfo - i.e., extended by Path(), which return the path of the file.

type ValidPropagate

type ValidPropagate int

ValidPropagate defines if validity shall be propagated to sub directories. Needed for Find()

const (
	NoneFromSuper    ValidPropagate = iota // no propagation to sub directories
	ValidFromSuper                         // propagate valid=true to sub directories
	InvalidFromSuper                       // propagate valid=false to sub directories
)

constants for Find(): propagation of validity to sub directories

Jump to

Keyboard shortcuts

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