path

package
v0.0.0-...-90c9d3a Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2010 License: BSD-3-Clause, GooglePatentClause Imports: 4 Imported by: 0

Documentation

Overview

The path package implements utility routines for manipulating slash-separated filename paths.

Index

Constants

This section is empty.

Variables

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

Functions

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 slashes with a single slash.
  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.

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 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 slash-separated element of path; it is empty if there is no dot.

func Join

func Join(elem ...string) string

Join joins any number of path elements into a single path, adding a separating slash 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 syntax used by pattern is:

pattern:
	{ term }
term:
	'*'         matches any sequence of non-/ characters
	'?'         matches any single non-/ 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 is when pattern is malformed.

func Split

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

Split splits path immediately following the final slash, separating it into a directory and file name component. If there is no slash in path, DirFile returns an empty dir and file set to path.

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, d *os.Dir) bool
	VisitFile(path string, d *os.Dir)
}

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

Jump to

Keyboard shortcuts

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