Documentation ¶
Overview ¶
Package fsutil is a collection of various filesystem utility functions.
Index ¶
- Variables
- func Copy(lhs, rhs fs.Filesystem) int
- func Find(dir string, n int) []string
- func Intersect(src, dir string) []string
- func Readdirnames(dir string) []string
- func Readdirpaths(dir string) []string
- func Readpaths(dir string) (files, dirs []string)
- func Rel(fs fs.Filesystem, rel string) fs.Filesystem
- func Tee(read, write fs.Filesystem) fs.Filesystem
- type Control
- func (c Control) Find(dir string, n int) []string
- func (c Control) Intersect(src, dir string) []string
- func (c Control) IntersectInclude(src, dir string) map[string][]string
- func (c Control) Readdirnames(dir string) []string
- func (c Control) Readdirpaths(dir string) []string
- func (c Control) Readpaths(dir string) (files, dirs []string)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var Default = Control{ FS: fs.Default, Hidden: false, }
Default is not documented yet, altougth it really hopes to be.
Functions ¶
func Copy ¶
func Copy(lhs, rhs fs.Filesystem) int
Copy copies directory tree structure from the path of the lhs to the root directory of the rhs filesystem. It returns sum of files and directories copied.
func Find ¶
Find globs into 'dir' directory, reading all files and directories except those, which names begin with a dot.
For n > 0 it descends for n directories deep. For n <= 0 it reads all directories.
On success it returns full paths for files and directories it found.
func Intersect ¶
Intersect returns a collection of paths which are the longest intersection between two directory trees - those trees have roots in 'src' and 'dir' directories. It does not glob into directories, which names begin with a dot.
Example ¶
For the following filesystem:
. ├── data │ └── github.com │ └── user │ └── example │ └── assets │ ├── css │ └── js └── src └── github.com └── user └── example
The following call:
names := glob.Intersect("src", "data")
Gives:
[]string{"github.com/user/example"}
func Readdirnames ¶
Readdirpaths reads all names of all subdirectories of the 'dir', except the ones which begin with a dot.
func Readdirpaths ¶
Readdirpaths reads all paths of all subdirectories of the 'dir', except the ones which begin with a dot.
func Readpaths ¶
Readpaths reads paths of all the files and directories of the 'dir' directory. If none files were found, the 'files' slice will be nil. If none directories were found, the 'dirs' slice will be nil. If the 'dir' was empty or error occured during accessing the filesystem, both slice will be empty.
func Rel ¶
func Rel(fs fs.Filesystem, rel string) fs.Filesystem
Rel returns a filesystem which prepends rel to each path passed to the fs.Filesystem methods it implements.
Example ¶
TODO(rjeczalik)
Output:
func Tee ¶
func Tee(read, write fs.Filesystem) fs.Filesystem
Tee returns a filesystem which writes file tree read from 'read' filesystem in the 'write' one. Every path passed to the Open, Create, Mkdir, MkdirAll and Readdir methods is created on the 'write' filesystem only if the call was sucessful. Tee can be used as a spy for recording file and/or directory access of the 'read' filesystem.
Types ¶
type Control ¶
type Control struct { // FS specifies the mechanism using which Glob accesses the filesystem. FS fs.Filesystem // Hidden tells whether the files and directories which name begin with a dot // should be included in the results. Hidden bool }
Control is the package control structure, allows for altering the behavior of its functions.
func (Control) Find ¶
Find globs into 'dir' directory, reading all files and directories.
For n > 0 it descends for n directories deep. For n <= 0 it reads all directories.
On success it returns full paths for files and directories it found.
func (Control) Intersect ¶
Intersect returns a collection of paths which are the longest intersection between two directory trees - those trees have roots in 'src' and 'dir' directories.
func (Control) IntersectInclude ¶
IntersectInclude is not documented yet, please see TestIntersectInclude for temporary usage details.
TODO(rjeczalik): document
func (Control) Readdirnames ¶
Readdirnames reads names of all the subdirectories of the 'dir' directory. If none were found or error occured during accessing the underlying filesystem, returned slice is nil.
func (Control) Readdirpaths ¶
Readdirpaths reads paths of all the subdirectories of the 'dir' directory. If none were found or error occured during accessing the underlying filesystem, returned slice is nil.
func (Control) Readpaths ¶
Readpaths reads paths of all the files and directories of the 'dir' directory. If none files were found, the 'files' slice will be nil. If none directories were found, the 'dirs' slice will be nil. If the 'dir' was empty or error occured during accessing the underlying filesystem, both slice will be empty.