File

package
v0.0.0-...-74cfed9 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2022 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// FILE_COVER_ALLOW 文件覆盖,允许
	CoverAllow = 1
	// FILE_COVER_IGNORE 文件覆盖,忽略
	CoverIgnore = 0
	// FILE_COVER_DENY 文件覆盖,禁止
	CoverDeny = -1

	// FILE_TREE_ALL 文件树,查找所有(包括目录和文件)
	TreeAll = 3
	// FILE_TREE_DIR 文件树,仅查找目录
	TreeDir = 2
	// FILE_TREE_FILE 文件树,仅查找文件
	TreeFile = 1
)
View Source
const (
	// FILE_TYPE_ANY 文件类型-任意
	FILE_TYPE_ANY = 0
	// FILE_TYPE_LINK 文件类型-链接文件
	FILE_TYPE_LINK = 1
	// FILE_TYPE_REGULAR 文件类型-常规文件(不包括链接)
	FILE_TYPE_REGULAR = 2
	// FILE_TYPE_COMMON 文件类型-普通文件(包括常规和链接)
	FILE_TYPE_COMMON = 3
)

Variables

This section is empty.

Functions

This section is empty.

Types

type File

type File byte

func (*File) AbsPath

func (*File) AbsPath(filePath string) string

AbsPath 获取绝对路径,path可允许不存在.

func (*File) AppendFile

func (*File) AppendFile(filePath string, data string) error

AppendFile 插入文件内容.

func (*File) Basename

func (*File) Basename(filePath string) string

Basename 返回路径中的文件名部分.

func (*File) Chmod

func (*File) Chmod(filePath string, fileMode os.FileMode) (res bool)

Chmod 批量改变路径权限模式(包括子目录和所属文件).fileMode为文件权限模式,dirMode为目录权限模式.

func (*File) CopyDir

func (toolFile *File) CopyDir(source string, dest string, coverType ...int) (int64, error)

CopyDir 拷贝源目录到目标目录,cover为枚举(FILE_COVER_ALLOW、FILE_COVER_IGNORE、FILE_COVER_DENY).

func (*File) CopyFile

func (toolFile *File) CopyFile(source string, dest string, coverType ...int) (int64, error)

CopyFile 拷贝源文件到目标文件,cover为枚举(FILE_COVER_ALLOW、FILE_COVER_IGNORE、FILE_COVER_DENY).

func (toolFile *File) CopyLink(source string, dest string) error

CopyLink 拷贝链接.

func (*File) CountLines

func (*File) CountLines(filePath string, cacheLength ...int) (int, error)

CountLines 统计文件行数.buffLength为缓冲长度,kb.

func (*File) DelDir

func (toolFile *File) DelDir(dir string, delRoot ...bool) error

DelDir 删除目录;delRoot为true时连该目录一起删除;为false时只清空该目录.

func (*File) DirSize

func (*File) DirSize(filePath string) int64

DirSize 获取目录大小(bytes字节).

func (*File) Dirname

func (toolFile *File) Dirname(filePath string) string

Dirname 返回路径中的目录部分,注意空路径或无目录的返回"." .

func (*File) Ext

func (toolFile *File) Ext(filePath string) string

Ext 获取文件的小写扩展名,不包括点"." .

func (*File) FastCopy

func (toolFile *File) FastCopy(source string, dest string) (int64, error)

FastCopy 快速拷贝源文件到目标文件,不做安全检查.

func (*File) FormatDir

func (*File) FormatDir(filePath string) string

FormatDir 格式化目录,将"\","//"替换为"/",且以"/"结尾.

func (*File) FormatPath

func (toolFile *File) FormatPath(filePath string) string

FormatPath 格式化路径

func (*File) Glob

func (*File) Glob(pattern string) ([]string, error)

Glob 寻找与模式匹配的文件路径.

func (*File) IsBinary

func (toolFile *File) IsBinary(filePath string) bool

IsBinary 是否二进制文件(且存在).

func (*File) IsDir

func (*File) IsDir(filePath string) bool

IsDir 是否目录(且存在).

func (*File) IsExecutable

func (*File) IsExecutable(filePath string) bool

IsExecutable 是否可执行文件.

func (*File) IsExist

func (*File) IsExist(filePath string) bool

IsExist 路径(文件/目录)是否存在.

func (*File) IsFile

func (toolFile *File) IsFile(filePath string, fileType ...ParamFileType) (res bool)

IsFile 判断文件是否为某类型的文件,且存在

func (*File) IsImg

func (toolFile *File) IsImg(filePath string) bool

IsImg 是否图片文件(仅检查后缀).

func (*File) IsLink(filePath string) bool

IsLink 是否链接文件(且存在).

func (*File) IsReadable

func (*File) IsReadable(filePath string) bool

IsReadable 路径是否可读.

func (*File) IsWritable

func (*File) IsWritable(filePath string) bool

IsWritable 路径是否可写.

func (*File) IsZip

func (*File) IsZip(filePath string) bool

IsZip 是否zip文件.

func (*File) Md5

func (*File) Md5(filePath string, length ...int) (string, error)

Md5 获取文件md5值,length指定结果长度32/16.

func (*File) Mime

func (*File) Mime(filePath string, fast bool) string

Mime 获取文件mime类型;fast为true时根据后缀快速获取;为false时读取文件头获取.

func (*File) Mkdir

func (*File) Mkdir(filePath string, mode os.FileMode) error

Mkdir 新建目录,允许多级目录.

func (*File) ModTime

func (*File) ModTime(filePath string) time.Time

ModTime 获取文件的修改时间戳,秒.

func (*File) Mode

func (*File) Mode(filePath string) (os.FileMode, error)

Mode 获取路径的权限模式.

func (*File) PathInfo

func (*File) PathInfo(filePath string, options int) map[string]string

PathInfo 获取文件路径的信息,options的值为-1: all; 1: dirname; 2: basename; 4: extension; 8: filename.

func (*File) ProjectPath

func (*File) ProjectPath() string

获取项目路径

func (*File) ReadFile

func (*File) ReadFile(filePath string) ([]byte, error)

ReadFile 读取文件内容.

func (*File) ReadFirstLine

func (*File) ReadFirstLine(filePath string) string

ReadFirstLine 读取文件首行.

func (*File) ReadInArray

func (*File) ReadInArray(filePath string) ([]string, error)

ReadInArray 把整个文件读入一个数组中,每行作为一个元素.

func (*File) ReadLastLine

func (*File) ReadLastLine(filePath string) string

ReadLastLine 读取文件末行.

func (*File) RealPath

func (*File) RealPath(filePath string) string

RealPath 返回规范化的真实绝对路径名,path必须存在.若路径不存在则返回空字符串.

func (*File) Remove

func (*File) Remove(filePath string) error

Remove 删除文件.

func (*File) Rename

func (*File) Rename(oldName, newName string) error

Rename 重命名文件或目录.

func (*File) SafeFileName

func (*File) SafeFileName(str string) string

SafeFileName 将文件名转换为安全可用的字符串.

func (*File) ShaX

func (*File) ShaX(filePath string, x uint16) (string, error)

ShaX 计算文件的 shaX 散列值,x为1/256/512.

func (*File) Size

func (*File) Size(filePath string) int64

Size 获取文件大小(bytes字节),注意:文件不存在或无法访问返回-1 .

func (*File) TarGz

func (toolFile *File) TarGz(src string, dstTar string, ignorePatterns ...string) (bool, error)

TarGz 打包压缩tar.gz;src为源文件或目录,dstTar为打包的路径名,ignorePatterns为要忽略的文件正则.

func (*File) ToBase64

func (toolFile *File) ToBase64(filePath string) (string, string, error)

ToBase64 读取图片文件,并转换为base64字符串.

func (*File) Touch

func (toolFile *File) Touch(filePath string, size int64) bool

Touch 快速创建指定大小的文件,size为字节.

func (*File) Tree

func (toolFile *File) Tree(filePath string, fileType int, recursive bool, filters ...FileFilter) []string

func (*File) UnTarGz

func (toolFile *File) UnTarGz(srcTar, dstDir string) (bool, error)

UnTarGz 将tar.gz文件解压缩;srcTar为压缩包,dstDir为解压目录.

func (*File) UnZip

func (toolFile *File) UnZip(srcZip, dstDir string) (bool, error)

UnZip 解压zip文件.srcZip为zip文件路径,dstDir为解压目录.

func (*File) WriteFile

func (*File) WriteFile(filePath string, data string, perm ...os.FileMode) error

WriteFile 将内容写入文件. filePath为文件路径,data为内容,perm为权限.

func (*File) Zip

func (toolFile *File) Zip(dst string, fpaths ...string) (bool, error)

Zip 将文件目录进行zip打包.fpaths为文件或目录的路径.

type FileFilter

type FileFilter func(string) bool

type ParamFileType

type ParamFileType uint8

Jump to

Keyboard shortcuts

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