...

Package file

import "simonwaldherr.de/go/golibs/file"
Overview
Index
Examples

Overview ▾

file wraps around the standard functions to simplify reading and writing on disk

Variables

var HomeDir string

func Clean

func Clean(fn string) error

func Copy

func Copy(from, to string) error

func Delete

func Delete(fn string) error

func Each

func Each(dirname string, recursive bool, fnc func(string, string, string, bool, os.FileInfo)) error

func Exists

func Exists(fn string) bool

func FakeHomeDir

func FakeHomeDir(dir string) string

func GetAbsolutePath

func GetAbsolutePath(fn string) (string, error)

GetAbsolutePath returns the absolute path to a file or dir if it is a relative path it is relative to the current working directory

Example

Code:

converted, err := file.GetAbsolutePath(".")
fmt.Println(converted, err)

func GetAbsolutePathByApp

func GetAbsolutePathByApp(fn string) (string, error)

GetAbsolutePathByApp returns the absolute path to a file or dir if it is a relative path it is relative to the Go Application source or binary

func GetHomeDir

func GetHomeDir() string

func IsDir

func IsDir(fn string) bool

func IsFile

func IsFile(fn string) bool
func IsSymlink(fn string) bool

func Read

func Read(fn string) (string, error)

Example

Code:

str, _ := file.Read("test.txt")
fmt.Println(str)

Output:

Lorem ipsum dolor sit amet, consectetur adipisici elit, sed eiusmod tempor incidunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquid ex ea commodi consequat. Quis aute iure reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint obcaecat cupiditat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

func ReadBlocks

func ReadBlocks(fn string, delim []string, fnc func(string) (string, error)) (string, error)

func ReadDir

func ReadDir(dn string) ([]string, error)

func ReadUntil

func ReadUntil(fn string, delim []string) (string, string, int, error)

func Rename

func Rename(from, to string) error

func SetHomeDir

func SetHomeDir() string

func Size

func Size(fn string) (int64, error)

Example

Code:

size, _ := file.Size("test.txt")
fmt.Println(size)

Output:

429

func Time

func Time(fn string) (time.Time, time.Time, time.Time, error)

func Write

func Write(fn, str string, append bool) error