file

package module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2022 License: MIT Imports: 5 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Exists

func Exists(pth string) (bool, error)

Exists returns true iff the given file or directory exists.

func IsDir

func IsDir(pth string) (bool, error)

IsDir returns true iff the given file exists and is a directory.

func IsRegular

func IsRegular(pth string) (bool, error)

IsRegular returns true iff the given file exists and is a regular file.

func RemoveDir

func RemoveDir(pth string) error

RemoveDir attempts to remove the directory at the given path. This will fail if the directory is non-empty.

func RemoveDirAll

func RemoveDirAll(pth string) error

RemoveDirAll attempts to remove the directory at the given path, along with the contents of the directory.

func RemoveFile

func RemoveFile(pth string) error

RemoveFile attempts to remove the file at the given path.

func SearchDir

func SearchDir(base string, target string) (pth string, err error)

SearchDir non-recursively searches the given base directory for the target file or directory. Upon success, returns the path to the target (including base).

func SearchDirs

func SearchDirs(baseDirs string, target string) (pth string, err error)

SearchDirs will non-recursively search the colon-separated list of directories for the first occurrence of the target file or directory. Upon success, returns the path to the target (including base). Will silently ignore any base directories that do not exist or are unreadable due to insufficient permissions.

func SearchRecursive

func SearchRecursive(root string, target string) (pth string, err error)

SearchRecursive recursively walks the file tree rooted at root. Any directories for which we do not have permission to read will be skipped. Symbolic links will not be followed. It will return the path (including the root) for the first file or directory matching "target". If no match is found, then returns the empty string.

func Walk

func Walk(root string) (<-chan string, <-chan error, chan<- struct{})

Walk recursively walks the file tree rooted at root. The paths to the regular files encountered (the root is included in the path) are passed down the first channel. Any directories for which we do not have permission to read will be skipped. Symbolic links will not be followed. Any errors encountered during the walk will be passed down the second channel (of type *WalkError), and the walk will continue. The third return value is a channel that can be closed to halt the walk.

Types

type WalkError

type WalkError struct {
	File string // The file
	Err  error  // The error
}

WalkError describes an error during a walk.

func (*WalkError) Cause

func (e *WalkError) Cause() error

Cause returns the underlying error.

func (*WalkError) Error

func (e *WalkError) Error() string

Error returns an error message.

Jump to

Keyboard shortcuts

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