find

package
v7.0.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2020 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Overview

Package find searches for files in a directory hierarchy recursively.

find can filter out files by file names, paths, and modes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Find

func Find(ctx context.Context, opt ...Set) <-chan *File

Find finds files according to the settings and matchers given.

e.g.

names := Find(ctx,
  WithRoot("/boot"),
  WithFilenameMatch("sda[0-9]"),
  WithDebugLog(log.Printf),
)

Types

type File

type File struct {
	// Name is the path relative to the root specified in WithRoot.
	Name string

	os.FileInfo
	Err error
}

File is a found file.

func (*File) String

func (f *File) String() string

String implements a fmt.Stringer for File.

String returns a string long-formatted like `ls` would format it.

type Set

type Set func(*finder)

func WithBasenameMatch

func WithBasenameMatch(pattern string, match func(pattern string, name string) (bool, error)) Set

WithBasenameMatch sets up a file base name filter.

func WithDebugLog

func WithDebugLog(l func(string, ...interface{})) Set

WithDebugLog logs messages to l.

func WithFilenameMatch

func WithFilenameMatch(pattern string) Set

WithFilenameMatch uses filepath.Match's shell file name matching to filter file base names.

func WithModeMatch

func WithModeMatch(mode, modeMask os.FileMode) Set

WithModeMatch ensures only files with fileMode & modeMask == mode are returned.

func WithPathMatch

func WithPathMatch(pattern string, match func(pattern string, path string) (bool, error)) Set

WithPathMatch sets up a file path filter.

The file path passed to match will be relative to the finder's root.

func WithRegexPathMatch

func WithRegexPathMatch(pattern string) Set

WithRegexPathMatch sets up a path filter using regex.

The file path passed to regexp.Match will be relative to the finder's root.

func WithRoot

func WithRoot(rootPath string) Set

WithRoot sets a root path for the file finder. Only descendants of the root will be returned on the channel.

func WithoutError

func WithoutError() Set

WithoutError filters out files with errors from being sent on the channel.

Jump to

Keyboard shortcuts

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