fsutil

package
v0.0.0-...-0f47780 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2014 License: MIT Imports: 6 Imported by: 1

Documentation

Overview

Package fsutil is a collection of various filesystem utility functions.

Index

Examples

Constants

This section is empty.

Variables

View Source
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

func Find(dir string, n int) []string

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

func Intersect(src, dir string) []string

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

func Readdirnames(dir string) []string

Readdirpaths reads all names of all subdirectories of the 'dir', except the ones which begin with a dot.

func Readdirpaths

func Readdirpaths(dir string) []string

Readdirpaths reads all paths of all subdirectories of the 'dir', except the ones which begin with a dot.

func Readpaths

func Readpaths(dir string) (files, dirs []string)

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

func (c Control) Find(dir string, n int) []string

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

func (c Control) Intersect(src, dir string) []string

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

func (c Control) IntersectInclude(src, dir string) map[string][]string

IntersectInclude is not documented yet, please see TestIntersectInclude for temporary usage details.

TODO(rjeczalik): document

func (Control) Readdirnames

func (c Control) Readdirnames(dir string) []string

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

func (c Control) Readdirpaths(dir string) []string

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

func (c Control) Readpaths(dir string) (files, dirs []string)

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.

Jump to

Keyboard shortcuts

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