fpath

package module
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2024 License: MIT Imports: 2 Imported by: 1

README

go-filepath

  • easily check whether a file is existing, whether it's a directory, etc. This is like a shortcut of "os" and "io/fs" in standard library.

Import

import "github.com/lsejx/go-filepath"



Example

check filepath
path := "/"
t, err := fpath.GetType(path)
t.IsExisting()    // true
t.IsNotExisting() // false
t.IsRegularFile() // false
t.IsDir()         // true
t.IsSymlink()     // false
t.IsDevice()      // false
t.IsCharDevice()  // false
t.IsPipe()        // false
t.IsSocket()      // false
t.IsIrregular()   // false

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Type

type Type struct {
	// contains filtered or unexported fields
}

func GetType

func GetType(path string) (Type, error)

GetType checks the filepath and returns struct that contains the result of checking. If os.Lstat returns non-nil error, GetType returns it.

func (Type) IsCharDevice

func (t Type) IsCharDevice() bool

IsCharDevice returns true if it's a character device file. IsDevice returns true when IsCharDevice returns true. This is based on io/fs.FileMode.

func (Type) IsDevice

func (t Type) IsDevice() bool

IsDevice returns true if it's a device file despite whether it's a block device or character device. This is based on io/fs.FileMode.

func (Type) IsDir

func (t Type) IsDir() bool

IsDir returns true if it's a directory. This is based on io/fs.FileMode.

func (Type) IsExisting

func (t Type) IsExisting() bool

IsExisting returns true on existing path despite whether it is a regular file, directory or special file. This is based on os.Stat.

func (Type) IsIrregular

func (t Type) IsIrregular() bool

IsIrregular returns true if it's non-regular file; nothing else is known about this file (see pkg.go.dev/io/fs#FileMode). This is based on io/fs.FileMode.

func (Type) IsNotExisting

func (t Type) IsNotExisting() bool

IsNotExisting returns NOT of IsExisting.

func (Type) IsPipe

func (t Type) IsPipe() bool

IsPipe returns true if it's a named pipe. This is based on io/fs.FileMode.

func (Type) IsRegularFile

func (t Type) IsRegularFile() bool

IsRegularFile returns true if it's a regular file (not a directory and a special file.) If it's a special file like device, pipe, symlink, socket, etc, this returns false. This is based on io/fs.FileMode.

func (Type) IsSocket

func (t Type) IsSocket() bool

IsSocket returns true if it's a socket. This is based on io/fs.FileMode.

func (t Type) IsSymlink() bool

IsSymlink returns true if it's a symbolic link. This is based on io/fs.FileMode.

Jump to

Keyboard shortcuts

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