go.astrophena.name/gen Module
An another static site generator.
This package is unmaintained.
package fileutil
import "go.astrophena.name/gen/fileutil"
Package fileutil contains utility functions for working with files and directories.
Index
- func CopyDirContents(src, dst string) error
- func CopyFile(src, dst string) error
- func Exists(path string) bool
- func Files(dir string, exts ...string) (files []string, err error)
- func Mkdir(dir string) error
Examples
Functions
func CopyDirContents
func CopyDirContents(src, dst string) error
CopyDirContents recursively copies contents of src to dst.
Example
package main import ( "log" "go.astrophena.name/gen/fileutil" ) func main() { if err := fileutil.CopyDirContents("phryne", "fisher"); err != nil { log.Fatal(err) } }
func CopyFile
func CopyFile(src, dst string) error
CopyFile copies the file src to dst.
Example
package main import ( "log" "go.astrophena.name/gen/fileutil" ) func main() { if err := fileutil.CopyFile("/etc/hostname", "/tmp/hostname"); err != nil { log.Fatal(err) } }
func Exists
func Exists(path string) bool
Exists returns true if a file or directory does exist and false otherwise.
Example
package main import ( "fmt" "go.astrophena.name/gen/fileutil" ) func main() { if fileutil.Exists("example") { fmt.Println("example exists") } else { fmt.Println("no example!") } }
func Files
func Files(dir string, exts ...string) (files []string, err error)
Files returns a slice of files in the directory dir recursively with extensions exts, or an error. If no file extensions are supplied, all files are returned.
Example
package main import ( "fmt" "path/filepath" "go.astrophena.name/gen/fileutil" ) func main() { dir := filepath.Join("testdata/files") fmt.Println(fileutil.Files(dir)) }
func Mkdir
func Mkdir(dir string) error
Mkdir creates the directory, if it does not already exist. It also creates parent directories as needed.
Example
package main import ( "log" "go.astrophena.name/gen/fileutil" ) func main() { if err := fileutil.Mkdir("example"); err != nil { log.Fatal(err) } }