Documentation
¶
Index ¶
- func MkTempFile(dir *Path, prefix string) (*os.File, error)
- type Path
- func (p *Path) Abs() (*Path, error)
- func (p *Path) Append() (*os.File, error)
- func (p *Path) Base() string
- func (p *Path) Canonical() *Path
- func (p *Path) Chtimes(atime, mtime time.Time) error
- func (p *Path) Clean() *Path
- func (p *Path) Clone() *Path
- func (p *Path) CopyDirTo(dst *Path) error
- func (p *Path) CopyTo(dst *Path) error
- func (p *Path) Create() (*os.File, error)
- func (p *Path) EqualsTo(other *Path) bool
- func (p *Path) EquivalentTo(other *Path) bool
- func (p *Path) Exist() bool
- func (p *Path) ExistCheck() (bool, error)
- func (p *Path) Ext() string
- func (p *Path) FollowSymLink() error
- func (p *Path) HasPrefix(prefixes ...string) bool
- func (p *Path) HasSuffix(suffixies ...string) bool
- func (p *Path) IsAbs() bool
- func (p *Path) IsDir() bool
- func (p *Path) IsDirCheck() (bool, error)
- func (p *Path) IsInsideDir(dir *Path) (bool, error)
- func (p *Path) IsNotDir() bool
- func (p *Path) Join(paths ...string) *Path
- func (p *Path) JoinPath(paths ...*Path) *Path
- func (p *Path) MarshalJSON() ([]byte, error)
- func (p *Path) MkTempDir(prefix string) (*Path, error)
- func (p *Path) Mkdir() error
- func (p *Path) MkdirAll() error
- func (p *Path) NotExist() bool
- func (p *Path) Open() (*os.File, error)
- func (p *Path) Parent() *Path
- func (p *Path) Parents() []*Path
- func (p *Path) ReadDir() (PathList, error)
- func (p *Path) ReadDirRecursive() (PathList, error)
- func (p *Path) ReadFile() ([]byte, error)
- func (p *Path) ReadFileAsLines() ([]string, error)
- func (p *Path) RelFrom(r *Path) (*Path, error)
- func (p *Path) RelTo(r *Path) (*Path, error)
- func (p *Path) Remove() error
- func (p *Path) RemoveAll() error
- func (p *Path) Rename(newpath *Path) error
- func (p *Path) Stat() (os.FileInfo, error)
- func (p *Path) String() string
- func (p *Path) ToAbs() error
- func (p *Path) Truncate() error
- func (p *Path) UnmarshalJSON(b []byte) error
- func (p *Path) WriteFile(data []byte) error
- type PathList
- func (p *PathList) Add(path *Path)
- func (p *PathList) AddAll(paths PathList)
- func (p *PathList) AddAllMissing(pathsToAdd PathList)
- func (p *PathList) AddIfMissing(path *Path)
- func (p *PathList) AsStrings() []string
- func (p *PathList) Clone() PathList
- func (p *PathList) Contains(pathToSearch *Path) bool
- func (p *PathList) ContainsEquivalentTo(pathToSearch *Path) bool
- func (p *PathList) FilterDirs()
- func (p *PathList) FilterOutDirs()
- func (p *PathList) FilterOutHiddenFiles()
- func (p *PathList) FilterOutPrefix(prefixes ...string)
- func (p *PathList) FilterOutSuffix(suffixies ...string)
- func (p *PathList) FilterPrefix(prefixes ...string)
- func (p *PathList) FilterSuffix(suffixies ...string)
- func (p *PathList) Len() int
- func (p *PathList) Less(i, j int) bool
- func (p *PathList) Sort()
- func (p *PathList) Swap(i, j int)
- func (p *PathList) ToAbs() error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MkTempFile ¶
MkTempFile creates a new temporary file in the directory dir with a name beginning with prefix, opens the file for reading and writing, and returns the resulting *os.File. If dir is nil, MkTempFile uses the default directory for temporary files (see paths.TempDir). Multiple programs calling TempFile simultaneously will not choose the same file. The caller can use f.Name() to find the pathname of the file. It is the caller's responsibility to remove the file when no longer needed.
Types ¶
type Path ¶
type Path struct {
// contains filtered or unexported fields
}
Path represents a path
func MkTempDir ¶
MkTempDir creates a new temporary directory in the directory dir with a name beginning with prefix and returns the path of the new directory. If dir is the empty string, TempDir uses the default directory for temporary files
func NewFromFile ¶
NewFromFile creates a new Path object using the path name obtained from the File object (see os.File.Name function).
func NullPath ¶
func NullPath() *Path
NullPath return the path to the /dev/null equivalent for the current OS
func WriteToTempFile ¶ added in v1.4.0
WriteToTempFile writes data to a newly generated temporary file. dir and prefix have the same meaning for MkTempFile. In case of success the Path to the temp file is returned.
func (*Path) Append ¶ added in v1.3.3
Append opens a file for append or creates it if the file doesn't exist.
func (*Path) Canonical ¶ added in v1.5.0
Canonical return a "canonical" Path for the given filename. The meaning of "canonical" is OS-dependent but the goal of this method is to always return the same path for a given file (factoring out all the possibile ambiguities including, for example, relative paths traversal, symlinks, drive volume letter case, etc).
func (*Path) Chtimes ¶
Chtimes changes the access and modification times of the named file, similar to the Unix utime() or utimes() functions.
func (*Path) Clean ¶
Clean Clean returns the shortest path name equivalent to path by purely lexical processing
func (*Path) CopyDirTo ¶
CopyDirTo recursively copies the directory denoted by the current path to the destination path. The source directory must exist and the destination directory must NOT exist (no implicit destination name allowed). Symlinks are not copied, they will be supported in future versions.
func (*Path) CopyTo ¶
CopyTo copies the contents of the file named src to the file named by dst. The file will be created if it does not already exist. If the destination file exists, all it's contents will be replaced by the contents of the source file. The file mode will be copied from the source and the copied data is synced/flushed to stable storage.
func (*Path) Create ¶ added in v1.2.0
Create creates or truncates a file. It calls os.Create on the underlying path.
func (*Path) EquivalentTo ¶
EquivalentTo return true if both paths are equivalent (they points to the same file even if they are lexicographically different) based on the current working directory.
func (*Path) Exist ¶
Exist return true if the file denoted by this path exists, false in any other case (also in case of error).
func (*Path) ExistCheck ¶
ExistCheck return true if the path exists or false if the path doesn't exists. In case the check fails false is returned together with the corresponding error.
func (*Path) FollowSymLink ¶
FollowSymLink transforms the current path to the path pointed by the symlink if path is a symlink, otherwise it does nothing
func (*Path) HasPrefix ¶
HasPrefix returns true if the file name has one of the given prefixes (the Base() method is used to obtain the file name used for the comparison)
func (*Path) IsDir ¶
IsDir returns true if the path exists and is a directory. In all the other cases (and also in case of any error) false is returned.
func (*Path) IsDirCheck ¶
IsDirCheck return true if the path exists and is a directory or false if the path exists and is not a directory. In all the other case false and the corresponding error is returned.
func (*Path) IsInsideDir ¶
IsInsideDir returns true if the current path is inside the provided dir
func (*Path) IsNotDir ¶
IsNotDir returns true if the path exists and is NOT a directory. In all the other cases (and also in case of any error) false is returned.
func (*Path) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface
func (*Path) MkTempDir ¶
MkTempDir creates a new temporary directory inside the path pointed by the Path object with a name beginning with prefix and returns the path of the new directory.
func (*Path) MkdirAll ¶
MkdirAll creates a directory named path, along with any necessary parents, and returns nil, or else returns an error
func (*Path) NotExist ¶
NotExist return true if the file denoted by this path DO NOT exists, false in any other case (also in case of error).
func (*Path) Open ¶ added in v1.1.0
Open opens a file for reading. It calls os.Open on the underlying path.
func (*Path) Parent ¶
Parent returns all but the last element of path, typically the path's directory or the parent directory if the path is already a directory
func (*Path) Parents ¶
Parents returns all the parents directories of the current path. If the path is absolute it starts from the current path to the root, if the path is relative is starts from the current path to the current directory. The path should be clean for this method to work properly (no .. or . or other shortcuts). This function does not performs any check on the returned paths.
func (*Path) ReadDir ¶
ReadDir returns a PathList containing the content of the directory pointed by the current Path
func (*Path) ReadDirRecursive ¶ added in v1.3.0
ReadDirRecursive returns a PathList containing the content of the directory and its subdirectories pointed by the current Path
func (*Path) ReadFileAsLines ¶
ReadFileAsLines reads the file named by filename and returns it as an array of lines. This function takes care of the newline encoding differences between different OS
func (*Path) RelFrom ¶ added in v1.4.0
RelFrom returns a relative Path that when joined with r is lexically equivalent to the current path.
For example paths.New("/my/path/ab/cd").RelFrom(paths.New("/my/path")) returns "ab/cd".
func (*Path) RelTo ¶
RelTo returns a relative Path that is lexically equivalent to r when joined to the current Path.
For example paths.New("/my/path/ab/cd").RelTo(paths.New("/my/path")) returns "../..".
func (*Path) RemoveAll ¶
RemoveAll removes path and any children it contains. It removes everything it can but returns the first error it encounters. If the path does not exist, RemoveAll returns nil (no error).
func (*Path) Rename ¶
Rename renames (moves) the path to newpath. If newpath already exists and is not a directory, Rename replaces it. OS-specific restrictions may apply when oldpath and newpath are in different directories. If there is an error, it will be of type *os.LinkError.
func (*Path) Stat ¶
Stat returns a FileInfo describing the named file. The result is cached internally for next queries. To ensure that the cached FileInfo entry is updated just call Stat again.
func (*Path) Truncate ¶
Truncate create an empty file named by path or if the file already exist it truncates it (delete all contents)
func (*Path) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface
type PathList ¶
type PathList []*Path
PathList is a list of Path
func NewPathList ¶
NewPathList creates a new PathList with the given paths
func (*PathList) AddAllMissing ¶
AddAllMissing adds all paths to the PathList excluding the paths already in the list
func (*PathList) AddIfMissing ¶
AddIfMissing adds a Path to the PathList if the path is not already in the list
func (*PathList) Contains ¶
Contains check if the list contains a path that match exactly (EqualsTo) to the specified path
func (*PathList) ContainsEquivalentTo ¶
ContainsEquivalentTo check if the list contains a path that is equivalent (EquivalentTo) to the specified path
func (*PathList) FilterDirs ¶
func (p *PathList) FilterDirs()
FilterDirs remove all entries except directories
func (*PathList) FilterOutDirs ¶
func (p *PathList) FilterOutDirs()
FilterOutDirs remove all directories entries
func (*PathList) FilterOutHiddenFiles ¶
func (p *PathList) FilterOutHiddenFiles()
FilterOutHiddenFiles remove all hidden files (files with the name starting with ".")
func (*PathList) FilterOutPrefix ¶
FilterOutPrefix remove all entries having the specified prefixes
func (*PathList) FilterOutSuffix ¶
FilterOutSuffix remove all entries having the specified suffix
func (*PathList) FilterPrefix ¶
FilterPrefix remove all entries not having one of the specified prefixes
func (*PathList) FilterSuffix ¶
FilterSuffix remove all entries not having the specified prefix