xfile

package
v1.0.9 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2020 License: MIT Imports: 16 Imported by: 6

Documentation

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 CopyDir

func CopyDir(src string, dst string) (err error)

复制文件夹

func CopyFile

func CopyFile(src, dst string) (err error)

复制文件

func Create

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

创建文件

func Dir

func Dir(path string) string

获取文件所在文件夹,如果path="",则返回"."

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

获取文件内容,文件不存在时返回nil

func GetBinContentsByTwoOffsets

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

从reader中获取从位置start到end之间的二进制数据

func GetBinContentsByTwoOffsetsByPath

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

从文件path中,获取从位置start到end之间的二进制数据

func GetBinContentsTilChar

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

在reader中,获取从start到字符char之间二进制数据,包含char在内

func GetBinContentsTilCharByPath

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

在文件path中,获取从start位置到字符char之间的二进制数据,包含char在内

func GetContents

func GetContents(path string) string

获取文件内容,返回字符串,文件不存在时返回空字符串

func GetNextCharOffset

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

从start之后查找char字符,如果找到返回找到位置,否则返回-1

func GetNextCharOffsetByPath

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

在文件path中从start之后查找字符char,找到则返回所在位置,否则返回-1

func Glob

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

按指定规则查找获取文件或文件夹

func Home

func Home() (string, error)

获取用户根目录

func Info

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

获取路径信息,Stat别名

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 Join

func Join(subPath ...string) string

以路径分隔符连接路径并返回

func MTime

func MTime(path string) int64

获取文件修改时间,秒

func MTimeMillisecond

func MTimeMillisecond(path string) int64

获取文件修改时间,毫秒

func MainPkgPath

func MainPkgPath() string

获取主项目目录

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)

Open opens file/directory readonly. 以只读方式打开文件或文件夹

func OpenFile

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

以指定文件打开文件或文件夹

func OpenWithFlag

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

以默认权限打开文件或文件夹

func OpenWithFlagPerm

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

以指定权限打开文件或文件夹

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

返回当前工作目录

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 Search(name string, prioritySearchPaths ...string) (realPath string, err error)

查找文件,找到返回文件路径,否则返回空字符串

func SelfDir

func SelfDir() string

获取当前程序所在路径

func SelfName

func SelfName() string

获取当前程序名称

func SelfPath

func SelfPath() string

获取当前程序所在路径

func Size

func Size(path string) int64

获取文件大小,返回字节数

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

临时目录

func Truncate

func Truncate(path string, size int) error

清空文件

Types

This section is empty.

Jump to

Keyboard shortcuts

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