gfile

package
v1.4.7 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 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

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

func Chmod

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

修改文件/目录权限

func Copy

func Copy(src string, dst string) error

文件复制

func Create

func Create(path string) error

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

func Dir

func Dir(path string) string

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

func DirNames

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

返回目录下的文件名列表

func Exists

func Exists(path string) bool

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

func Ext

func Ext(path string) string

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

func FormatSize

func FormatSize(raw float64) string

格式化文件大小

func GetBinContents

func GetBinContents(path string) []byte

(二进制)读取文件内容

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)

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

func Home

func Home() (string, error)

获取用户主目录

func Info

func Info(path string) *os.FileInfo

获取文件或目录信息

func IsDir

func IsDir(path string) bool

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

func IsFile

func IsFile(path string) bool

判断所给路径是否为文件

func IsReadable

func IsReadable(path string) bool

文件是否可读

func IsWritable

func IsWritable(path string) bool

文件是否可写

func MTime

func MTime(path string) int64

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

func MTimeMillisecond

func MTimeMillisecond(path string) int64

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

func MainPkgPath

func MainPkgPath() string

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

func Mkdir

func Mkdir(path string) error

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

func Move

func Move(src string, dst string) error

文件移动/重命名

func Open

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

打开文件(os.O_RDWR|os.O_CREATE, 0666)

func OpenWithFlag

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

打开文件(带flag)

func OpenWithFlagPerm

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

打开文件(带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

获取当前工作目录(SelfDir()方法的别名)

func ReadableSize

func ReadableSize(path string) string

格式化文件大小

func RealPath

func RealPath(path string) string

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

func Remove

func Remove(path string) error

文件/目录删除

func Rename

func Rename(src string, dst string) error

文件移动/重命名

func ScanDir

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

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

func SelfDir

func SelfDir() string

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

func SelfPath

func SelfPath() string

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

func Size

func Size(path string) int64

文件大小(bytes)

func TempDir

func TempDir() string

系统临时目录

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