fileutil

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: May 18, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CopyFile

func CopyFile(src, dst string, replace, jump bool) error

CopyFile 复制文件(源路径, 目标路径, 重复覆盖, 重复忽略)

func CopyFiles

func CopyFiles(src, dst string, replace, jump bool, walk WalkCallback) error

CopyFiles 复制文件夹 (源路径, 目标路径, 重复覆盖, 重复忽略, 每个路径操作结果回调(可以nil)) walk 返回err则停止下一个拷贝

func FormatFileSize

func FormatFileSize(fileSize int64) (size string)

FormatFileSize 字节的单位转换 保留两位小数

func GetCreateTime

func GetCreateTime(path string) (time.Time, error)

GetCreateTime 获取创建时间

func GetDirList

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

GetDirList 获取一级子目录名字(包含文件|文件夹,无序)

func GetFileInfo

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

GetFileInfo 获取文件信息对象

func GetFileSize

func GetFileSize(path string) (int64, error)

GetFileSize 获取文件大小

func GetModifyTime

func GetModifyTime(path string) (time.Time, error)

GetModifyTime 获取修改时间

func GetSHA256

func GetSHA256(r io.Reader) (string, error)

GetSHA256 获取sha256

func GetWriter

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

GetWriter 获取只写文件对象 O_RDONLY: 只读模式(read-only) O_WRONLY: 只写模式(write-only) O_RDWR: 读写模式(read-write) O_APPEND: 追加模式(append) O_CREATE: 文件不存在就创建(create a new file if none exists.) O_EXCL: 与 O_CREATE 一起用, 构成一个新建文件的功能, 它要求文件必须不存在 O_SYNC: 同步方式打开,即不使用缓存,直接写入硬盘 O_TRUNC: 打开并清空文件

func IsAcrossDiskError

func IsAcrossDiskError(err error) bool

IsAcrossDiskError 是否是跨磁盘错误

func IsDir

func IsDir(path string) bool

IsDir 是否是文件夹

func IsExist

func IsExist(path string) bool

IsExist 文件/夹是否存在

func IsExistError

func IsExistError(err error) bool

IsExistError 是否是目标位置已经存在的错误

func IsFile

func IsFile(path string) bool

IsFile 是否是文件

func IsNotExistError

func IsNotExistError(err error) bool

IsNotExistError 是否是目标位置不存在的错误

func Mkdir

func Mkdir(path string) error

Mkdir 创建文件夹

func MkdirAll

func MkdirAll(path string) error

MkdirAll 创建文件夹-多级

func MoveFiles

func MoveFiles(src, dst string, replace, jump bool) error

MoveFiles 移动文件|夹, 如果存在的话就列表后逐一移动 (源路径, 目标路径, 重复覆盖, 重复忽略)

func MoveFilesAcrossDisk

func MoveFilesAcrossDisk(src, dst string, replace, jump bool, walk WalkCallback) error

MoveFilesAcrossDisk 移动文件|文件夹,可跨分区移动(源路径, 目标路径, 重复覆盖, 重复忽略, 每个路径操作结果回调(可以nil))

func MoveFilesByCopying

func MoveFilesByCopying(src, dst string, replace, jump bool, walk WalkCallback) error

MoveFilesByCopying 移动文件|夹(拷贝+删除) (源路径, 目标路径, 重复覆盖, 重复忽略, 每个路径操作结果回调(可以nil))

func OpenFile

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

OpenFile 获取文件信息对象

func PathExist

func PathExist(op, path string) error

PathExist 路径已经存在的错误

func PathNotExist

func PathNotExist(op, path string) error

PathNotExist 路径不存在的错误

func ReadFileAsJSON

func ReadFileAsJSON(path string, v interface{}) error

ReadFileAsJSON 读取Json文件

func ReadFileAsText

func ReadFileAsText(path string) (string, error)

ReadFileAsText 读取Json文件

func RemoveAll

func RemoveAll(file string) error

RemoveAll 删除文件

func RemoveFile

func RemoveFile(file string) error

RemoveFile 删除文件

func Rename

func Rename(old, newName string) error

Rename 重命名

func WriteFileAsJSON

func WriteFileAsJSON(path string, v interface{}) error

WriteFileAsJSON 写入Json文件

func WriteTextFile

func WriteTextFile(path, text string) error

WriteTextFile 写入文本文件

Types

type WalkCallback

type WalkCallback func(src, dst string, err error) error

WalkCallback (源路径, 目标路径, 错误信息) 错误. 子文件操作回调 一般用于子文件操作时间较长的操作, 如: MoveFilesAcrossDisk, MoveFilesByCopying, CopyFiles. 返回 非空error则终止下一步操作

Jump to

Keyboard shortcuts

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