gfile

package
v1.5.17 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2019 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package gfile provides easy-to-use operations for file system.

文件管理.

Index

Constants

View Source
const (
	// 文件分隔符
	Separator = string(filepath.Separator)
)

Variables

This section is empty.

Functions

func Basename

func Basename(path string) string

See filepath.Base.

获取指定文件路径的文件名称

func Chmod

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

See os.Chmod.

修改文件/目录权限

func Copy

func Copy(src string, dst string) error

Copy file from src to dst.

文件复制. @TODO 支持目录复制.

func Create

func Create(path string) (*os.File, error)

Create file with given path recursively.

给定文件的绝对路径创建文件。

func Dir

func Dir(path string) string

See filepath.Dir.

获取指定文件路径的目录地址绝对路径.

func DirNames

func DirNames(path string) ([]string, error)

Get sub-file names of path.

返回目录下的文件名列表

func Exists

func Exists(path string) bool

Check whether given path exist.

判断所给路径文件/文件夹是否存在

func Ext

func Ext(path string) string

See filepath.Ext.

获取指定文件路径的文件扩展名(包含"."号)

func FormatSize

func FormatSize(raw float64) string

格式化文件大小

func GetBinContents

func GetBinContents(path string) []byte

(二进制)读取文件内容,如果文件不存在或者读取失败,返回nil。

func GetBinContentsByTwoOffsets

func GetBinContentsByTwoOffsets(reader io.ReaderAt, start int64, end int64) []byte

获得文件内容中两个offset之间的内容 [start, end)

func GetBinContentsByTwoOffsetsByPath

func GetBinContentsByTwoOffsetsByPath(path string, start int64, end int64) []byte

获得文件内容中两个offset之间的内容 [start, end)

func GetBinContentsTilChar

func GetBinContentsTilChar(reader io.ReaderAt, char byte, start int64) ([]byte, int64)

获得文件内容直到下一个指定字节的位置(返回值包含该位置字符内容)

func GetBinContentsTilCharByPath

func GetBinContentsTilCharByPath(path string, char byte, start int64) ([]byte, int64)

获得文件内容直到下一个指定字节的位置(返回值包含该位置字符内容)

func GetContents

func GetContents(path string) string

(文本)读取文件内容

func GetNextCharOffset

func GetNextCharOffset(reader io.ReaderAt, char byte, start int64) int64

获得文件内容下一个指定字节的位置

func GetNextCharOffsetByPath

func GetNextCharOffsetByPath(path string, char byte, start int64) int64

获得文件内容下一个指定字节的位置

func Glob

func Glob(pattern string, onlyNames ...bool) ([]string, error)

Glob returns the names of all files matching pattern or nil if there is no matching file. The syntax of patterns is the same as in Match. The pattern may describe hierarchical names such as /usr/*/bin/ed (assuming the Separator is '/').

Glob ignores file system errors such as I/O errors reading directories. The only possible returned error is ErrBadPattern, when pattern is malformed.

文件名正则匹配查找,第二个可选参数指定返回的列表是否仅为文件名(非绝对路径),默认返回绝对路径

func Home

func Home() (string, error)

Get absolute home directory path of current user.

获取用户主目录

func Info

func Info(path string) (os.FileInfo, error)

See Stat.

Stat 方法的别名。

func IsDir

func IsDir(path string) bool

Check whether given path a directory.

判断所给路径是否为文件夹

func IsFile

func IsFile(path string) bool

Check whether given path a file(not a directory).

判断所给路径是否为文件

func IsReadable

func IsReadable(path string) bool

Check whether given <path> is readable.

文件是否可读(支持文件/目录)

func IsWritable

func IsWritable(path string) bool

Check whether given <path> is writable.

文件是否可写(支持文件/目录) @TODO 改进性能,利用 golang.org/x/sys 来实现跨平台的权限判断。

func MTime

func MTime(path string) int64

文件修改时间(时间戳,秒)

func MTimeMillisecond

func MTimeMillisecond(path string) int64

文件修改时间(时间戳,毫秒)

func MainPkgPath

func MainPkgPath() string

Get absolute file path of main file, which contains the entrance function main. Available in develop environment.

获取入口函数文件所在目录(main包文件目录), **仅对源码开发环境有效(即仅对生成该可执行文件的系统下有效)**

func Mkdir

func Mkdir(path string) error

Create directories recursively.

给定目录的绝对路径创建目录(递归创建)。

func Move

func Move(src string, dst string) error

Move renames (moves) src to dst path.

文件移动/重命名

func Open

func Open(path string) (*os.File, error)

Open file/directory with readonly.

只读打开文件

func OpenFile

func OpenFile(path string, flag int, perm os.FileMode) (*os.File, error)

Open file/directory with given <flag> and <perm>.

打开文件(带flag&perm)

func OpenWithFlag

func OpenWithFlag(path string, flag int) (*os.File, error)

Open file/directory with default perm and given <flag>.

打开文件(带flag)

func OpenWithFlagPerm

func OpenWithFlagPerm(path string, flag int, perm int) (*os.File, error)

Open file/directory with given <flag> and <perm>.

打开文件(带flag&perm)

func PutBinContents

func PutBinContents(path string, content []byte) error

(二进制)写入文件内容

func PutBinContentsAppend

func PutBinContentsAppend(path string, content []byte) error

(二进制)追加内容到文件末尾

func PutContents

func PutContents(path string, content string) error

(文本)写入文件内容

func PutContentsAppend

func PutContentsAppend(path string, content string) error

(文本)追加内容到文件末尾

func Pwd

func Pwd() string

Get current working directory absolute path.

获取当前工作目录(注意与SelfDir的区别).

func ReadableSize

func ReadableSize(path string) string

格式化文件大小

func RealPath

func RealPath(path string) string

See filepath.Abs.

将所给定的路径转换为绝对路径 并判断文件路径是否存在,如果文件不存在,那么返回空字符串

func Remove

func Remove(path string) error

Remove file/directory with <path> parameter.

文件/目录删除

func Rename

func Rename(src string, dst string) error

Rename renames (moves) src to dst path.

文件移动/重命名.

func ScanDir

func ScanDir(path string, pattern string, recursive ...bool) ([]string, error)

Get all sub-files(absolute) of given <path>, can be recursively with given parameter <recursive> true.

打开目录,并返回其下一级文件列表(绝对路径),按照文件名称大小写进行排序,支持目录递归遍历。

func SelfDir

func SelfDir() string

Get absolute directory path of current running process(binary).

获取当前执行文件的目录绝对路径

func SelfPath

func SelfPath() string

Get absolute file path of current running process(binary).

获取当前执行文件的绝对路径

func Size

func Size(path string) int64

文件大小(bytes)

func Stat

func Stat(path string) (os.FileInfo, error)

Stat returns a FileInfo describing the named file. If there is an error, it will be of type *PathError.

获取文件或目录信息.

func TempDir

func TempDir() string

See os.TempDir().

系统临时目录

func Truncate

func Truncate(path string, size int) error

Truncate

Types

This section is empty.

Jump to

Keyboard shortcuts

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