Documentation ¶
Overview ¶
Package file is a package for dealing with strongly typed paths and files in an OS agnostic manner.
Index ¶
- func Copy(ctx context.Context, dst Path, src Path) error
- func IsJunction(path Path) bool
- func Junction(link, target Path) error
- func Link(link, target Path) error
- func Mkdir(dir Path) error
- func Mkfile(p Path) error
- func Move(dst, src Path) error
- func Relink(link, target Path, method func(link, target Path) error) error
- func Remove(f Path) error
- func RemoveAll(f Path) error
- func SanitizePath(p string) string
- func Symlink(link, target Path) error
- func Unzip(ctx context.Context, archive string, outputDir string) error
- func ZIP(out io.Writer, in Path) error
- type Path
- func (p Path) Basename() string
- func (p Path) ChangeExt(ext string) Path
- func (p Path) Contains(other Path) bool
- func (p Path) Exists() bool
- func (p Path) Ext() string
- func (p Path) Files() PathList
- func (p Path) Glob(pattern ...string) PathList
- func (p Path) Info() os.FileInfo
- func (p Path) IsDir() bool
- func (p Path) IsEmpty() bool
- func (p Path) IsExecutable() bool
- func (p Path) Join(join ...string) Path
- func (p Path) MarshalJSON() ([]byte, error)
- func (p Path) Matches(patterns ...string) bool
- func (p Path) NoExt() Path
- func (p Path) Parent() Path
- func (p Path) RelativeTo(base Path) (string, error)
- func (p *Path) Set(value string) error
- func (p Path) Slash() string
- func (p Path) Smash() (Path, string, string)
- func (p Path) Split() (Path, string)
- func (p Path) SplitExt() (Path, string)
- func (p Path) String() string
- func (p Path) System() string
- func (p Path) Timestamp() time.Time
- func (p Path) URL() *url.URL
- func (p *Path) UnmarshalJSON(data []byte) error
- func (p Path) Walk(walkFn func(path Path, err error) error) error
- type PathList
- func (l PathList) Append(paths ...Path) PathList
- func (l PathList) AsSet() PathSet
- func (l PathList) Contains(path Path) bool
- func (l PathList) Find(fragment string) Rooted
- func (l PathList) Len() int
- func (l PathList) Less(i, j int) bool
- func (l PathList) Matching(patterns ...string) PathList
- func (l PathList) NotMatching(patterns ...string) PathList
- func (l PathList) RootOf(p Path) Rooted
- func (l *PathList) Set(value string) error
- func (l PathList) String() string
- func (l PathList) Swap(i, j int)
- type PathSet
- func (s PathSet) Append(paths ...Path) PathSet
- func (s PathSet) AsList() PathList
- func (s PathSet) Contains(path Path) bool
- func (s PathSet) Matching(patterns ...string) PathSet
- func (s PathSet) NotMatching(patterns ...string) PathSet
- func (s PathSet) RootOf(p Path) Rooted
- func (s PathSet) Union(other PathSet) PathSet
- type Rooted
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsJunction ¶
IsJunction returns false as junctions are not supported by this platform.
func SanitizePath ¶
SanitizePath returns the path p with illegal file path characters replaced with '-'.
Types ¶
type Path ¶
type Path struct {
// contains filtered or unexported fields
}
Path is a clean absolute path with platform specific separators.
func Abs ¶
Abs is the primary constructor of new Path objects from strings using either the / or system separator.
func ExecutablePath ¶
func ExecutablePath() Path
ExecutablePath returns the path to the running executable.
func FindExecutable ¶
FindExecutable searches the system search path for the named binary, and returns a non empty Path if found. OS executable file extensions (".exe") are automatically considered when searching.
func TempWithExt ¶
TempWithExt creates a new temp file with the given name and extension and returns its path.
func (Path) ChangeExt ¶
ChangeExt returns a new Path with the extension changed to ext. ext should being with a '.' to change extension, or be an empty string to remove the extension.
func (Path) Ext ¶
Ext returns the extension of the path, including the '.', or an empty string if the path has no extension.
func (Path) Glob ¶
Glob adds each pattern to the path in turn, and uses filepath.Glob to resolve that pattern to a list of files.
func (Path) IsExecutable ¶
IsExecutable returns true if the file at p.value exists, is executable and is not a directory.
func (Path) Join ¶
Join returns a path formed from joining this base with a child path. If there are any / characters in the strings, they will be converted to they system separator.
func (Path) MarshalJSON ¶
MarshalJSON implements custom JSON marshalling to write paths as simple JSON strings.
func (Path) Parent ¶
Parent returns the parent directory of the path, if it has one. It will return the canonical version of the path if it is a root.
func (Path) RelativeTo ¶
RelativeTo returns the path of this File relative to base.
func (Path) SplitExt ¶
SplitExt returns the path excluding the file extension and the file extension. The extension includes the '.'.
func (Path) URL ¶
URL returns the full absolute path using the / separator prefixed by the URL file scheme.
func (*Path) UnmarshalJSON ¶
UnmarshalJSON implements custom JSON unmarshalling to read strings a paths.
type PathList ¶
type PathList []Path
PathList is a list of file paths.
func SplitList ¶
SplitList splits a string on the system path list separator, and then resolves each produced string to a Path, returning the paths produced as a PathList.
func (PathList) Find ¶
Find searches the paths in the list for on that when joined with the path fragment produces an existing file name.
func (PathList) Len ¶
Len is the number of elements in the collection, so PathList implements sort.Interface.
func (PathList) Less ¶
Less reports whether the element with index i should sort before the element with index j, so PathList implements sort.Interface.
func (PathList) NotMatching ¶
NotMatching returns the list of files that does not match any supplied pattern.
type PathSet ¶
type PathSet struct {
// contains filtered or unexported fields
}
PathSet is a list of file paths that does not allow duplicates.
func (PathSet) Append ¶
Append is analogous to the append function, except it also suppresses duplicates. It copies the set and then adds the supplied paths.
func (PathSet) NotMatching ¶
NotMatching returns the set of paths that do not match any pattern.