xfile

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2024 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// TypeAll list dir and file
	TypeAll int = iota
	// TypeDir list only dir
	TypeDir
	// TypeFile list only file
	TypeFile
)

Variables

This section is empty.

Functions

func Append added in v0.0.4

func Append(fpath string, data []byte) (err error)

Append appends bytes data to file

func AppendText added in v0.0.4

func AppendText(fpath, text string) (err error)

AppendText appends string data to file

func Chmod added in v0.0.4

func Chmod(fpath string, mode os.FileMode) error

Chmod chmods to path without recursion

func ChmodAll added in v0.0.4

func ChmodAll(root string, mode os.FileMode) error

ChmodAll chmods to path and children, returns the first error it encounters

func Chown added in v0.0.4

func Chown(fpath string, uid, gid int) error

Chown chowns to path without recursion

func ChownAll added in v0.0.4

func ChownAll(root string, uid, gid int) error

ChownAll chowns to path and children, returns the first error it encounters

func Copy

func Copy(src, dst string) error

Copy ...

func GetConfigDir

func GetConfigDir(paths ...string) (string, error)

GetConfigDir ...

func GetCurrentDir

func GetCurrentDir() string

GetCurrentDir ...

func GetFileDir

func GetFileDir(filepath string) string

GetFileDir ...

func GetFileExt

func GetFileExt(file string) string

GetFileExt ...

func GetFileName

func GetFileName(filepath string) string

GetFileName ...

func GetFileNameWithoutExt

func GetFileNameWithoutExt(filepath string) string

GetFileNameWithoutExt ...

func GetFilePathWithoutExt

func GetFilePathWithoutExt(filepath string) string

GetFilePathWithoutExt ...

func GetHomeDir

func GetHomeDir() string

GetHomeDir ...

func IsDir

func IsDir(filepath string) bool

IsDir ...

func IsExist

func IsExist(filepath string) bool

IsExist ...

func IsFile

func IsFile(filepath string) bool

IsFile ...

func IsImage

func IsImage(filepath string) bool

IsImage ...

func LineContent

func LineContent(filepath string, numbers ...int) map[int]string

LineContent ...

func LineCount

func LineCount(filepath string) int

LineCount ...

func ListDirs

func ListDirs(dir string, isRecursive ...bool) []string

ListDirs ...

func ListFiles

func ListFiles(dir string, match string, isRecursive ...bool) []string

ListFiles ...

func Md5

func Md5(path string) (string, error)

Md5 file md5

func MineType

func MineType(filepath string) string

MineType ...

func New added in v0.0.4

func New(fpath string) (*os.File, error)

New opens a file for new and return fd

func NewFile added in v0.0.4

func NewFile(fpath string, isAppend bool) (*os.File, error)

NewFile opens a file and return fd

func Read

func Read(filepath string) string

Read ...

func ReadFirstLine added in v0.0.4

func ReadFirstLine(fpath string) (line string, err error)

ReadFirstLine returns first NOT empty line

func ReadJSON

func ReadJSON(filepath string, data interface{}) error

ReadJSON read JSON file data

func ReadLastLine added in v0.0.4

func ReadLastLine(fpath string) (line string, err error)

ReadLastLine returns last NOT empty line

func ReadLastNLines added in v0.0.3

func ReadLastNLines(filePath string, n int) ([]string, error)

ReadLastNLines ...

func ReadLines added in v0.0.4

func ReadLines(fpath string, n int) (lines []string, err error)

ReadLines returns N lines of file

func ReaderMineType

func ReaderMineType(r io.Reader) string

ReaderMineType ...

func ReverseRead added in v0.0.3

func ReverseRead(fileName string, lineNum uint) ([]string, error)

ReverseRead 读取文件的最后 N 行

func Shadow

func Shadow(filepath string) string

Shadow 根据当前文件名称取其影分身 /tmp/abc.txt => /tmp/abc_1.txt

func Size

func Size(filepath string) int64

Size ...

func SizeText

func SizeText(size int64) string

SizeText ...

func Temp

func Temp(filenames ...string) string

Temp ...

func Write

func Write(filepath, str string) error

Write ...

func WriteByte added in v0.0.4

func WriteByte(fpath string, data []byte) (err error)

Write writes bytes data to file

func WriteJSON

func WriteJSON(filepath string, data interface{}, pretty ...bool) error

WriteJSON write data to JSON file

func WriteText added in v0.0.4

func WriteText(fpath, text string) (err error)

WriteText writes string data to file

Types

type LsFile added in v0.0.4

type LsFile struct {
	Type int
	Path string
	Name string
}

LsFile is list file info

func ListDir added in v0.0.4

func ListDir(fpath string, ftype, n int) (ls []LsFile, err error)

ListDir lists dir without recursion

func ListDirAll added in v0.0.4

func ListDirAll(fpath string, ftype, n int) (ls []LsFile, err error)

ListDirAll lists dir and children, filter by type, returns up to n

Jump to

Keyboard shortcuts

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