Documentation ¶
Overview ¶
Package gfile provides easy-to-use operations for file system.
文件管理.
Index ¶
- Constants
- func Basename(path string) string
- func Chmod(path string, mode os.FileMode) error
- func Copy(src string, dst string) error
- func Create(path string) (*os.File, error)
- func Dir(path string) string
- func DirNames(path string) ([]string, error)
- func Exists(path string) bool
- func Ext(path string) string
- func FormatSize(raw float64) string
- func GetBinContents(path string) []byte
- func GetBinContentsByTwoOffsets(reader io.ReaderAt, start int64, end int64) []byte
- func GetBinContentsByTwoOffsetsByPath(path string, start int64, end int64) []byte
- func GetBinContentsTilChar(reader io.ReaderAt, char byte, start int64) ([]byte, int64)
- func GetBinContentsTilCharByPath(path string, char byte, start int64) ([]byte, int64)
- func GetContents(path string) string
- func GetNextCharOffset(reader io.ReaderAt, char byte, start int64) int64
- func GetNextCharOffsetByPath(path string, char byte, start int64) int64
- func Glob(pattern string, onlyNames ...bool) ([]string, error)
- func Home() (string, error)
- func Info(path string) (os.FileInfo, error)
- func IsDir(path string) bool
- func IsFile(path string) bool
- func IsReadable(path string) bool
- func IsWritable(path string) bool
- func MTime(path string) int64
- func MTimeMillisecond(path string) int64
- func MainPkgPath() string
- func Mkdir(path string) error
- func Move(src string, dst string) error
- func Open(path string) (*os.File, error)
- func OpenFile(path string, flag int, perm os.FileMode) (*os.File, error)
- func OpenWithFlag(path string, flag int) (*os.File, error)
- func OpenWithFlagPerm(path string, flag int, perm int) (*os.File, error)
- func PutBinContents(path string, content []byte) error
- func PutBinContentsAppend(path string, content []byte) error
- func PutContents(path string, content string) error
- func PutContentsAppend(path string, content string) error
- func Pwd() string
- func ReadableSize(path string) string
- func RealPath(path string) string
- func Remove(path string) error
- func Rename(src string, dst string) error
- func ScanDir(path string, pattern string, recursive ...bool) ([]string, error)
- func SelfDir() string
- func SelfPath() string
- func Size(path string) int64
- func Stat(path string) (os.FileInfo, error)
- func TempDir() string
- func Truncate(path string, size int) error
Constants ¶
const ( // 文件分隔符 Separator = string(filepath.Separator) )
Variables ¶
This section is empty.
Functions ¶
func GetBinContentsByTwoOffsets ¶
获得文件内容中两个offset之间的内容 [start, end)
func GetBinContentsByTwoOffsetsByPath ¶
获得文件内容中两个offset之间的内容 [start, end)
func GetBinContentsTilChar ¶
获得文件内容直到下一个指定字节的位置(返回值包含该位置字符内容)
func GetBinContentsTilCharByPath ¶
获得文件内容直到下一个指定字节的位置(返回值包含该位置字符内容)
func GetNextCharOffset ¶
获得文件内容下一个指定字节的位置
func GetNextCharOffsetByPath ¶
获得文件内容下一个指定字节的位置
func Glob ¶
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 IsWritable ¶
Check whether given <path> is writable.
文件是否可写(支持文件/目录) @TODO 改进性能,利用 golang.org/x/sys 来实现跨平台的权限判断。
func MainPkgPath ¶
func MainPkgPath() string
Get absolute file path of main file, which contains the entrance function main. Available in develop environment.
获取入口函数文件所在目录(main包文件目录), **仅对源码开发环境有效(即仅对生成该可执行文件的系统下有效)**
func PutBinContentsAppend ¶
(二进制)追加内容到文件末尾
func ScanDir ¶
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).
获取当前执行文件的绝对路径
Types ¶
This section is empty.