import "path/filepath"
Package filepath implements utility routines for manipulating filename pathsin a way compatible with the target operating system-defined file paths.
const ( Separator = '/'// OS-specific path separator ListSeparator = 0// OS-specific path list separator)
const ( Separator = '\\'// OS-specific path separator ListSeparator = ':'// OS-specific path list separator)
const ( Separator = '/'// OS-specific path separator ListSeparator = ':'// OS-specific path list separator)
const ( SeparatorString = string(Separator) ListSeparatorString = string(ListSeparator))
var ErrBadPattern = os.NewError("syntax error in pattern")
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 currentworking directory to turn it into an absolute path. The absolutepath name for a given file is not guaranteed to be unique.
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(path string) string
Clean returns the shortest path name equivalent to pathby purely lexical processing. It applies the following rulesiteratively 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, Cleanreturns the string ".".
See also Rob Pike, “Lexical File Names in Plan 9 orGetting 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 symboliclinks.If path is relative it will be evaluated relative to the current directory.
func Ext(path string) string
Ext returns the file name extension used by path.The extension is the suffix beginning at the final dotin the final element of path; it is empty if there isno dot.
func FromSlash(path string) string
FromSlash returns the result of replacing each slash ('/') characterin path with a separator character.
func Glob(pattern string) (matches []string, err os.Error)
Glob returns the names of all files matching pattern or nilif there is no matching file. The syntax of patterns is the sameas 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(path string) bool
IsAbs returns true if the path is absolute.
func Join(elem ...string) string
Join joins any number of path elements into a single path, addinga Separator if necessary. All empty strings are ignored.
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 ccharacter-range:c matches character c (c != '\\', '-', ']')'\\' c matches character clo '-' 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(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 baseand file set to path.
func SplitList(path string) []string
SplitList splits a list of paths joined by the OS-specific ListSeparator.
func ToSlash(path string) string
ToSlash returns the result of replacing each separator characterin path with a slash ('/') character.
func Walk(root string, v Visitor, errors chan<- os.Error)
Walk walks the file tree rooted at root, calling v.VisitDir orv.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 errorto the channel. Otherwise Walk discards the error.
Visitor methods are invoked for corresponding file tree entriesvisited by Walk. The parameter path is the full path of f relativeto root.
type Visitor interface { VisitDir(path string, f *os.FileInfo) bool VisitFile(path string, f *os.FileInfo)}
release.r57.1 8276. Except as noted, this content is licensed under aCreative Commons Attribution 3.0 License.