pathlib

package module
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 21, 2020 License: MIT Imports: 6 Imported by: 1

README

pathlib

Simple Path type and helper methods for Go in the spirit of Python's pathlib.

In addition to providing many convenience methods, using the Path type provides more type safety than simply passing strings around.

myPath := Path("/foo/bar/baz.boo")

More docs on pkg.go.dev

Package report card

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Path

type Path string

Path type alias

func (Path) Age

func (p Path) Age(now time.Time) (time.Duration, error)

Age returns the last modification time of the Path, if it exists.

func (Path) Exists

func (p Path) Exists() bool

Exists returns true if the Path exists.

func (Path) Glob

func (p Path) Glob(pattern string) ([]Path, error)

Glob returns a list of Paths that match the pattern within the directory.

func (Path) IsDir

func (p Path) IsDir() bool

IsDir returns true if the Path is a directory. Note that false is returned if the Path does not exist.

func (Path) IsFile

func (p Path) IsFile() bool

IsFile returns true if the Path is a file. Note that false is returned if the Path does not exist.

func (Path) JoinPath

func (p Path) JoinPath(paths ...Path) Path

JoinPath returns any number of Paths joined by the OS specific path separator (eg. / or \).

func (Path) Mkdir

func (p Path) Mkdir() error

Mkdir creates the directory Path, including any parent directories that need to be created along the way.

func (Path) Name

func (p Path) Name() string

Name returns only the last portion of the Path as a string.

func (Path) Open

func (p Path) Open(mode string) (*os.File, error)

Open opens the Path with the specified mode with 0755 permissions. If the Path does not exist, it creates it.

func (Path) OpenWithPermissions

func (p Path) OpenWithPermissions(mode string, perms os.FileMode) (*os.File, error)

OpenWithPermissions opens the Path with the specified mode and permissions. If the Path does not exist, it creates it.

func (Path) Parent

func (p Path) Parent() Path

Parent returns the last directory in the Path. For a file, it returns the directory that the file is in. For a directory, it just returns the directory, not the directory above it.

func (Path) Permissions

func (p Path) Permissions() (os.FileMode, error)

Permissions returns the Path's permissions as from os.Stat().

func (Path) ReadBytes

func (p Path) ReadBytes() ([]byte, error)

ReadBytes reads all the bytes from a file Path.

func (Path) RelativeTo added in v0.1.2

func (p Path) RelativeTo(base Path) (Path, error)

RelativeTo returns how this path is relative to the input Path, if at all.

func (Path) Rename

func (p Path) Rename(target Path) error

Rename changes the name of the file to the target Path (essentially a move).

func (Path) Resolve

func (p Path) Resolve() (Path, error)

Resolve returns the absolute form of the Path, if it exists.

func (Path) Rmdir

func (p Path) Rmdir() error

Rmdir removes a directory, but will return an error if there are items within that directory (see RmdirRecursive).

func (Path) RmdirRecursive

func (p Path) RmdirRecursive() error

RmdirRecursive removes a directory and all items within it.

func (Path) Touch

func (p Path) Touch() error

Touch creates a file at the Path if it does not already exist.

func (p Path) Unlink() error

Unlink removes a file Path, but will return an error if the Path is a directory (see Rmdir).

func (Path) WithSuffix

func (p Path) WithSuffix(suffix string) Path

WithSuffix returns a new Path with the specified suffix (file extension). If the Path has no existing extension, the new extension will be added. If the Path has an extension, it will be replaced.

func (Path) WriteBytes

func (p Path) WriteBytes(data []byte) error

WriteBytes writes the bytes to the Path.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL