Documentation ¶
Overview ¶
Package fileutil provides helper functions for working with files and directories.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CopyDirContents ¶
CopyDirContents recursively copies contents of the src directory to dst or returns an error otherwise.
Example ¶
package main import ( "log" "astrophena.me/gen/pkg/fileutil" ) func main() { if err := fileutil.CopyDirContents("phryne", "fisher"); err != nil { log.Fatal(err) } }
Output:
func CopyFile ¶
CopyFile copies the src file to dst or returns an error otherwise. Any existing file will be overwritten and it will not copy file attributes.
Example ¶
package main import ( "log" "astrophena.me/gen/pkg/fileutil" ) func main() { if err := fileutil.CopyFile("/etc/hostname", "/tmp/hostname"); err != nil { log.Fatal(err) } }
Output:
func Exists ¶
Exists returns true if a file or directory exists and false otherwise.
Example ¶
package main import ( "fmt" "astrophena.me/gen/pkg/fileutil" ) func main() { if fileutil.Exists("example") { fmt.Println("example exists") } else { fmt.Println("no example!") } }
Output:
func Files ¶
Files returns a slice of files in the directory dir recursively, with file extensions exts, or an error. If no file extensions are supplied, all files are returned.
Example ¶
package main import ( "fmt" "path/filepath" "astrophena.me/gen/pkg/fileutil" ) func main() { dir := filepath.Join("testdata/files") fmt.Println(fileutil.Files(dir)) }
Output:
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.