fileutil

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: May 1, 2021 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package fileutil contains utility functions for working with files and directories.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

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)
	}
}
Output:

func CopyFile

func CopyFile(src, dst string) error

CopyFile copies the file src to dst, creating missing directories, if needed.

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)
	}
}
Output:

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!")
	}
}
Output:

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))
}
Output:

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)
	}
}
Output:

Types

This section is empty.

Jump to

Keyboard shortcuts

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