file

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2021 License: GPL-3.0 Imports: 9 Imported by: 1

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 EscapePattern

func EscapePattern(s string) string

EscapePattern escapes special characters in pattern strings for usage in filepath.Glob() or filepath.Match() See: https://godoc.org/path/filepath#Match

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 IsSub

func IsSub(path, sub string) (bool, error)

IsSub returns true if sub is a sub path of path,otherwise false is returned. The function is taken from https://stackoverflow.com/questions/28024731/check-if-given-path-is-a-subdirectory-of-another-in-golang

func MD5

func MD5(path string) ([]byte, error)

MD5 calculates the md5 hash of a file

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 PathRelCopy

func PathRelCopy(srcBase, path, dstBase string) (string, error)

PathRelCopy determines first a relative path that is lexically equivalent to path when joined to srcBase with an intervening separator. If this is successful, it returns a path joined from dstBase, a separator and the relative path from the previous step.

func PathTrunk

func PathTrunk(p string) string

PathTrunk returns the file path without the file extension. E.g. Trunk("/home/test/abc.mp3") return "/home/test/abc"

func RemoveEmpty

func RemoveEmpty(f string) error

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

func RenameAll

func RenameAll(pattern string, path string) error

RenameAll moves all files that match pattern to path

func SplitPath

func SplitPath(path string) []string

SplitPath splits the path of a file into the different folders and files.

func Suffix

func Suffix(f string) string

Suffix return the suffix of a file without the dot. If the file name contains no dot, an empty string is returned

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 return 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