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
- Variables
- func Abs(path string) (string, os.Error)
- func Base(path string) string
- func Clean(path string) string
- func EvalSymlinks(path string) (string, os.Error)
- func Ext(path string) string
- func FromSlash(path string) string
- func Glob(pattern string) (matches []string, err os.Error)
- func IsAbs(path string) bool
- func Join(elem ...string) string
- func Match(pattern, name string) (matched bool, err os.Error)
- func Split(path string) (dir, file string)
- func SplitList(path string) []string
- func ToSlash(path string) string
- func Walk(root string, v Visitor, errors chan<- os.Error)
- type Visitor
Constants ¶
const ( Separator = os.PathSeparator ListSeparator = os.PathListSeparator )
Variables ¶
var ErrBadPattern = os.NewError("syntax error in pattern")
Functions ¶
func Abs ¶
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 ¶
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 ¶
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:
- Replace multiple Separator elements with a single one.
- Eliminate each . path name element (the current directory).
- Eliminate each inner .. path name element (the parent directory) along with the non-.. element that precedes it.
- 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 ¶
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 ¶
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 ¶
FromSlash returns the result of replacing each slash ('/') character in path with a separator character.
func Glob ¶
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 Join ¶
Join joins any number of path elements into a single path, adding a Separator if necessary. All empty strings are ignored.
func Match ¶
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 ¶
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 ToSlash ¶
ToSlash returns the result of replacing each separator character in path with a slash ('/') character.
func Walk ¶
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.