file

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2022 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

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

Index

Examples

Constants

This section is empty.

Variables

View Source
var HomeDir string

Functions

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
package main

import (
	"fmt"
	"simonwaldherr.de/go/golibs/file"
)

func main() {
	converted, err := file.GetAbsolutePath(".")
	fmt.Println(converted, err)
}
Output:

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
package main

import (
	"fmt"
	"simonwaldherr.de/go/golibs/file"
)

func main() {
	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
package main

import (
	"fmt"
	"simonwaldherr.de/go/golibs/file"
)

func main() {
	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

Types

This section is empty.

Jump to

Keyboard shortcuts

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