pathlib

package module
v0.0.0-...-742166d Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2019 License: MIT Imports: 6 Imported by: 2

README

Go Report Card license

pathlib

A golang path library, it is easy to use. Similar to Python patblib.

该项目目前处于积极发展期😀,欢迎 issues

Installation

go get -u github.com/small-tk/pathlib

Enjoy


package main

import "github.com/small-tk/pathlib"

func main (){
	p := New("test.txt")

	fmt.Println(p.Absolute())
	fmt.Println(p.Cwd())
	fmt.Println(p.Parent())
	fmt.Println(p.Touch())

	fmt.Println(p.Unlink())
	fmt.Println(p.MkDir(os.ModePerm, true))
	fmt.Println(p.RmDir())
	fmt.Println(p.Open())
	fmt.Println(p.Chmod(os.ModePerm))
	fmt.Println(p.Chmod(os.ModePerm))

	fmt.Println(p.Exists())
	fmt.Println(p.IsDir())
	fmt.Println(p.IsFile())
	fmt.Println(p.IsAbs())
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Path

type Path struct {
	Path string
}

Path

func New

func New(path string) *Path

New Returns a new path.

func (*Path) Absolute

func (p *Path) Absolute() (*Path, error)

Absolute Returns an absolute representation of path.

func (*Path) Chmod

func (p *Path) Chmod(mode os.FileMode) error

Chmod changes the mode of the named file to mode.

func (*Path) Cwd

func (p *Path) Cwd() (*Path, error)

Cwd Return a new path pointing to the current working directory.

func (*Path) Exists

func (p *Path) Exists() bool

Exists reports current path parent exists.

func (*Path) IsAbs

func (p *Path) IsAbs() bool

IsAbs reports whether the path is absolute.

func (*Path) IsDir

func (p *Path) IsDir() bool

IsDir reports Whether this path is a directory.

func (*Path) IsFile

func (p *Path) IsFile() bool

IsFile reports Whether this path is a regular file.

func (*Path) JoinPath

func (p *Path) JoinPath(elem ...string) *Path

JoinPath Returns a new path, Combine current path with one or several arguments

func (*Path) MkDir

func (p *Path) MkDir(mode os.FileMode, parents bool) (err error)

MkDir Create a new directory at this given path.

func (*Path) Open

func (p *Path) Open() ([]byte, error)

Open Reads the file named by filename and returns the contents.

func (*Path) Parent

func (p *Path) Parent() (*Path, error)

Parent Return a new path for current path parent.

func (*Path) RmDir

func (p *Path) RmDir() error

RmDir Remove this directory. The directory must be empty.

func (*Path) Touch

func (p *Path) Touch() error

Touch Create creates the named file with mode 0666 (before umask), regardless of whether it exists.

func (p *Path) Unlink() error

Unlink Remove this file or link.

Jump to

Keyboard shortcuts

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