filepath

package
v0.0.0-...-e758773 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2011 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Overview

Package filepath implements utility routines for manipulating filename paths in a way compatible with the target operating system-defined file paths.

Index

Constants

View Source
const (
	Separator     = os.PathSeparator
	ListSeparator = os.PathListSeparator
)

Variables

View Source
var ErrBadPattern = os.NewError("syntax error in pattern")

Functions

func Abs

func Abs(path string) (string, os.Error)

Abs returns an absolute representation of path. If the path is not absolute it will be joined with the current working directory to turn it into an absolute path. The absolute path name for a given file is not guaranteed to be unique.

func Base

func Base(path string) string

Base returns the last element of path. Trailing path separators are removed before extracting the last element. If the path is empty, Base returns ".". If the path consists entirely of separators, Base returns a single separator.

func Clean

func Clean(path string) string

Clean returns the shortest path name equivalent to path by purely lexical processing. It applies the following rules iteratively until no further processing can be done:

  1. Replace multiple Separator elements with a single one.
  2. Eliminate each . path name element (the current directory).
  3. Eliminate each inner .. path name element (the parent directory) along with the non-.. element that precedes it.
  4. Eliminate .. elements that begin a rooted path: that is, replace "/.." by "/" at the beginning of a path, assuming Separator is '/'.

If the result of this process is an empty string, Clean returns the string ".".

See also Rob Pike, “Lexical File Names in Plan 9 or Getting Dot-Dot right,” http://plan9.bell-labs.com/sys/doc/lexnames.html

func EvalSymlinks(path string) (string, os.Error)

EvalSymlinks returns the path name after the evaluation of any symbolic links. If path is relative it will be evaluated relative to the current directory.

func Ext

func Ext(path string) string

Ext returns the file name extension used by path. The extension is the suffix beginning at the final dot in the final element of path; it is empty if there is no dot.

func FromSlash

func FromSlash(path string) string

FromSlash returns the result of replacing each slash ('/') character in path with a separator character.

func Glob

func Glob(pattern string) (matches []string, err os.Error)

Glob returns the names of all files matching pattern or nil if there is no matching file. The syntax of patterns is the same as in Match. The pattern may describe hierarchical names such as /usr/*/bin/ed (assuming the Separator is '/'). The only possible error return occurs when the pattern is malformed.

func IsAbs

func IsAbs(path string) bool

IsAbs returns true if the path is absolute.

func Join

func Join(elem ...string) string

Join joins any number of path elements into a single path, adding a Separator if necessary. All empty strings are ignored.

func Match

func Match(pattern, name string) (matched bool, err os.Error)

Match returns true if name matches the shell file name pattern. The pattern syntax is:

pattern:
	{ term }
term:
	'*'         matches any sequence of non-Separator characters
	'?'         matches any single non-Separator character
	'[' [ '^' ] { character-range } ']'
	            character class (must be non-empty)
	c           matches character c (c != '*', '?', '\\', '[')
	'\\' c      matches character c

character-range:
	c           matches character c (c != '\\', '-', ']')
	'\\' c      matches character c
	lo '-' hi   matches character c for lo <= c <= hi

Match requires pattern to match all of name, not just a substring. The only possible error return occurs when the pattern is malformed.

func Split

func Split(path string) (dir, file string)

Split splits path immediately following the final Separator, partitioning it into a directory and a file name components. If there are no separators in path, Split returns an empty base and file set to path.

func SplitList

func SplitList(path string) []string

SplitList splits a list of paths joined by the OS-specific ListSeparator.

func ToSlash

func ToSlash(path string) string

ToSlash returns the result of replacing each separator character in path with a slash ('/') character.

func Walk

func Walk(root string, v Visitor, errors chan<- os.Error)

Walk walks the file tree rooted at root, calling v.VisitDir or v.VisitFile for each directory or file in the tree, including root. If v.VisitDir returns false, Walk skips the directory's entries; otherwise it invokes itself for each directory entry in sorted order. An error reading a directory does not abort the Walk. If errors != nil, Walk sends each directory read error to the channel. Otherwise Walk discards the error.

Types

type Visitor

type Visitor interface {
	VisitDir(path string, f *os.FileInfo) bool
	VisitFile(path string, f *os.FileInfo)
}

Visitor methods are invoked for corresponding file tree entries visited by Walk. The parameter path is the full path of f relative to root.

Jump to

Keyboard shortcuts

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