fs

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 6, 2018 License: BSD-3-Clause Imports: 3 Imported by: 287

README

Filesystem Package

https://godoc.org/github.com/kr/fs

Documentation

Overview

Package fs provides filesystem-related functions.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FileSystem

type FileSystem interface {

	// ReadDir reads the directory named by dirname and returns a
	// list of directory entries.
	ReadDir(dirname string) ([]os.FileInfo, error)

	// Lstat returns a FileInfo describing the named file. If the file is a
	// symbolic link, the returned FileInfo describes the symbolic link. Lstat
	// makes no attempt to follow the link.
	Lstat(name string) (os.FileInfo, error)

	// Join joins any number of path elements into a single path, adding a
	// separator if necessary. The result is Cleaned; in particular, all
	// empty strings are ignored.
	//
	// The separator is FileSystem specific.
	Join(elem ...string) string
}

FileSystem defines the methods of an abstract filesystem.

type Walker

type Walker struct {
	// contains filtered or unexported fields
}

Walker provides a convenient interface for iterating over the descendants of a filesystem path. Successive calls to the Step method will step through each file or directory in the tree, including the root. The files are walked in lexical order, which makes the output deterministic but means that for very large directories Walker can be inefficient. Walker does not follow symbolic links.

Example
package main

import (
	"fmt"
	"os"

	"github.com/kr/fs"
)

func main() {
	walker := fs.Walk("/usr/lib")
	for walker.Step() {
		if err := walker.Err(); err != nil {
			fmt.Fprintln(os.Stderr, err)
			continue
		}
		fmt.Println(walker.Path())
	}
}
Output:

func Walk

func Walk(root string) *Walker

Walk returns a new Walker rooted at root.

func WalkFS

func WalkFS(root string, fs FileSystem) *Walker

WalkFS returns a new Walker rooted at root on the FileSystem fs.

func (*Walker) Err

func (w *Walker) Err() error

Err returns the error, if any, for the most recent attempt by Step to visit a file or directory. If a directory has an error, w will not descend into that directory.

func (*Walker) Path

func (w *Walker) Path() string

Path returns the path to the most recent file or directory visited by a call to Step. It contains the argument to Walk as a prefix; that is, if Walk is called with "dir", which is a directory containing the file "a", Path will return "dir/a".

func (*Walker) SkipDir

func (w *Walker) SkipDir()

SkipDir causes the currently visited directory to be skipped. If w is not on a directory, SkipDir has no effect.

func (*Walker) Stat

func (w *Walker) Stat() os.FileInfo

Stat returns info for the most recent file or directory visited by a call to Step.

func (*Walker) Step

func (w *Walker) Step() bool

Step advances the Walker to the next file or directory, which will then be available through the Path, Stat, and Err methods. It returns false when the walk stops at the end of the tree.

Jump to

Keyboard shortcuts

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