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 Clean(path string) string
- func EvalSymlinks(path string) (string, error)
- func FromSlash(path string) string
- func HasPrefix(p, prefix string) bool
- func IsAbs(path string) bool
- func Join(elem ...string) string
- func Rel(basepath, targpath string) (string, error)
- func ToSlash(path string) string
- func VolumeName(path string) (v string)
- func Walk(root string, walkFn WalkFunc) error
- type VisitData
- type WalkFunc
- type WalkState
Constants ¶
const ( Separator = os.PathSeparator ListSeparator = os.PathListSeparator )
Variables ¶
var LstatP = &lstat
var SkipDir = errors.New("skip this directory")
SkipDir is used as a return value from WalkFuncs to indicate that the directory named in the call is to be skipped. It is not returned as an error by any function.
Functions ¶
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 '/'.
The returned path ends in a slash only if it represents a root directory, such as "/" on Unix or `C:\` on Windows.
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 the result will be relative to the current directory, unless one of the components is an absolute symbolic link.
func FromSlash ¶
FromSlash returns the result of replacing each slash ('/') character in path with a separator character. Multiple slashes are replaced by multiple separators.
func Join ¶
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.
func Rel ¶
Rel returns a relative path that is lexically equivalent to targpath when joined to basepath with an intervening separator. That is, Join(basepath, Rel(basepath, targpath)) is equivalent to targpath itself. On success, the returned path will always be relative to basepath, even if basepath and targpath share no elements. An error is returned if targpath can't be made relative to basepath or if knowing the current working directory would be necessary to compute it.
func ToSlash ¶
ToSlash returns the result of replacing each separator character in path with a slash ('/') character. Multiple separators are replaced by multiple slashes.
func VolumeName ¶
VolumeName returns leading volume name. Given "C:\foo\bar" it returns "C:" under windows. Given "\\host\share\foo" it returns "\\host\share". On other platforms it returns "".
Types ¶
type WalkFunc ¶
WalkFunc is the type of the function called for each file or directory visited by Walk. The path argument contains the argument to Walk as a prefix; that is, if Walk is called with "dir", which is a directory containing the file "a", the walk function will be called with argument "dir/a". The info argument is the os.FileInfo for the named path.
If there was a problem walking to the file or directory named by path, the incoming error will describe the problem and the function can decide how to handle that error (and Walk will not descend into that directory). If an error is returned, processing stops. The sole exception is that if path is a directory and the function returns the special value SkipDir, the contents of the directory are skipped and processing continues as usual on the next file.