Documentation ¶
Overview ¶
Package dirtree implements utility routines to list files in a deterministic and cross-patform manner.
Index ¶
- func Sprint(root string, opts ...Option) (string, error)
- func SprintFS(fsys fs.FS, root string, opts ...Option) (string, error)
- func Write(w io.Writer, root string, opts ...Option) error
- func WriteFS(w io.Writer, fsys fs.FS, root string, opts ...Option) error
- type Depth
- type Entry
- type FileType
- type Ignore
- type IncludeRoot
- type Match
- type Option
- type PrintMode
- type Type
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Sprint ¶
Sprint walks the directory rooted at root and returns a string containing the list of files.
It's a wrapper around Write(...) provided for convenience.
func SprintFS ¶
SprintFS walks the directory rooted at root in the given filesystem and returns the list of files.
It's a wrapper around WriteFS(...) provided for convenience.
func Write ¶
Write walks the directory rooted at root and prints one file per line into w.
A variable number of options can be provided to control the limit the files printed and/or the amount of information printed for each of them.
Types ¶
type Depth ¶
type Depth int
The Depth option indicates how many levels of directories below root should we recurse into. 0, the default, means there's no limit.
type Entry ¶
type Entry struct { Path string RelPath string Type FileType Size int64 Checksum string // contains filtered or unexported fields }
An Entry holds gathered information about a particular file.
func List ¶
List walks the directory rooted at root and returns entries.
A variable number of options can be provided to control the limit the files printed and/or the amount of information gathered for each of them.
type Ignore ¶
type Ignore string
The Ignore option allows to ignore files matching a pattern. The path relative to the chosen root is matched against the pattern. Ignore follows the syntax used and described with the filepath.Match function. Before checking if it matches a pattern, a path is first converted to its slash ('/') based version, to ensure cross-platform consistency of the dirtree package.
Ignore can be provided multiple times to ignore multiple patterns. A file is ignored from the listing as long as at it matches at least one Ignore pattern. Also, Ignore has precedence over Match.
type IncludeRoot ¶
type IncludeRoot bool
ExcludeRoot is the option controlling whether the root directory should be printed when listing its content.
type Match ¶
type Match string
The Match option limits the listing to files that match a pattern. The path relative to the chosen root is matched against the pattern. Match follows the syntax used and described with the filepath.Match function. Before checking if it matches a pattern, a path is first converted to its slash ('/') based version, to ensure cross-platform consistency of the dirtree package.
Match can be provided multiple times to match multiple patterns. A file is included in the listing as long as at it matches at least one Match pattern, unless it matches an Ignore pattern (since Ignore has precedence over Match).
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
Option is the interface implemented by dirtree types used to control what to list and how to list it.
var ExcludeRoot Option = IncludeRoot(false)
The ExcludeRoot option hides the root directory from the list.
type PrintMode ¶
type PrintMode uint32
A PrintMode represents the amount of information to print about a file, next to its filename. PrintMode is a bit set. Somewhat related to os.FileMode and fs.FileMode but much less detailed.
const ( // ModeType indicates if file is a directory, a regular file or something // else. It prints 'd', 'f' or '?' respectively. ModeType PrintMode = 1 << iota // ModeSize reports the length in bytes for regular files, "1234b" for // example, or nothing for other types where size is not applicable (it // would be OS-dependent). ModeSize // ModeCRC32 computes and reports the CRC-32 checksum for regular files. For // other file types, or for files which permissions prevent reading, it // shows n/a (i.e. not applicable). Example "crc=294a245b" or "crc=n/a" ModeCRC32 // ModeDefault is a mask showing file type and size. ModeDefault PrintMode = ModeType | ModeSize // ModeAll is a mask showing all information about a file. ModeAll PrintMode = ModeType | ModeSize | ModeCRC32 )