file

package
v0.0.0-...-4873089 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2021 License: Apache-2.0 Imports: 11 Imported by: 5

Documentation

Index

Constants

View Source
const (
	// TimeFormat defines the format of time to save to the file.
	TimeFormat = "2006-01-02 15:04:05.000"
)

Variables

This section is empty.

Functions

func BaseDir

func BaseDir(dirs []string) string

BaseDir returns the common directory for a slice of directories.

func DirsUnder

func DirsUnder(dirPath string) ([]string, error)

DirsUnder list dirs under dirPath

func DoesExists

func DoesExists(filename string) bool

DoesExists checks if a file/directory exists.

func DoesNotExists

func DoesNotExists(filename string) bool

DoesNotExists checks if a file/directory not exists.

func ExistsAsDir

func ExistsAsDir(filename string) bool

ExistsAsDir checks if a file exists and is a directory before we try using it to prevent further errors.

func ExistsAsFile

func ExistsAsFile(filename string) bool

ExistsAsFile checks if a file exists and is not a directory before we try using it to prevent further errors.

func HomeDirExpand

func HomeDirExpand(dir string) string

HomeDirExpand expands the ~(home directory) from the dir.

func InsureDir

func InsureDir(fp string) error

InsureDir insure dir exist

func IsExist

func IsExist(fp string) bool

IsExist checks whether a file or directory exists. It returns false when the file or directory does not exist.

func ReadBytes

func ReadBytes(filename string) []byte

ReadBytes reads bytes from the file.

func ReadTime

func ReadTime(filename string, defaultValue string) (time.Time, error)

ReadTime reads the time.Time from the given file.

func ReadValue

func ReadValue(filename, defaultValue string) (string, error)

func SingleFileExists

func SingleFileExists(name string) error

SingleFileExists 检查文件是否存在,并且不是目录

func ToBytes

func ToBytes(filePath string) ([]byte, error)

ToBytes reads the file to a byte slice.

func ToString

func ToString(filePath string) (string, error)

ToString reads the file content to string.

func ToTrimString

func ToTrimString(filePath string) (string, error)

ToTrimString reads the file to a trimmed string.

func WriteBytes

func WriteBytes(filePath string, b []byte) (int, error)

WriteBytes writes byte slice to file.

func WriteString

func WriteString(filePath string, s string) (int, error)

WriteString writes string to file.

func WriteTime

func WriteTime(filename string, v time.Time) error

WriteTime writes the time.Time to the given file.

func WriteValue

func WriteValue(filename string, value string) error

WritValue writes a string value to the file.

Types

type DirMode

type DirMode int

DirMode means file is single file or directory.

const (
	// UnknownDirMode means unknown file or directory.
	UnknownDirMode DirMode = iota
	// DirectoryMode means directory.
	DirectoryMode
	// SingleFileMode means single file.
	SingleFileMode
)

func GetFileMode

func GetFileMode(name string) (DirMode, error)

GetFileMode tells the name is a directory or not

type ExistsEnum

type ExistsEnum int

ExistsEnum is the file exits enumeration.

const (
	// Exists means the file exists.
	Exists ExistsEnum = iota
	// NotExists means the file not exists.
	NotExists
	// Unknown means unknown state.
	Unknown
)

func Stat

func Stat(name string) ExistsEnum

Stat stats the file.

func StatE

func StatE(name string) (ExistsEnum, error)

StatE stats the file.

Jump to

Keyboard shortcuts

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