fileUtil

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: May 2, 2025 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendStrWithWriter

func AppendStrWithWriter(writer *bufio.Writer, content string) (w *bufio.Writer, re error)

func CheckExist

func CheckExist(src string) bool

CheckExist 检查文件是否存在

func CheckFileExist

func CheckFileExist(filepath string) bool

判断文件是否存在(filepath 文件的绝对路径)

func CheckPermission

func CheckPermission(src string) bool

CheckPermission 检查文件权限

func CopyFile

func CopyFile(source, target string, over bool) error

CopyFile over 是否覆盖

func CreatePath

func CreatePath(path string, perm os.FileMode) bool

func CreatePathWithDefaultMode

func CreatePathWithDefaultMode(path string) string

func CurrPath

func CurrPath() string

func CurrPath2

func CurrPath2() string

func DeleteFile

func DeleteFile(target string)

func Exist

func Exist(path string) bool

func FileMD5

func FileMD5(filePath string) (string, error)

func FormatSize

func FormatSize(fileSize int64) (size string)

FormatSize 转换文件大小的单位

func GetAbs

func GetAbs(path string) string

func GetCurrentAbPath

func GetCurrentAbPath() string

最终方案-全兼容

func GetCurrentAbPathByCaller

func GetCurrentAbPathByCaller() string

获取当前执行文件绝对路径(go run)

func GetCurrentAbPathByExecutable

func GetCurrentAbPathByExecutable() string

获取当前执行程序所在的绝对路径

func GetCurrentProjectPath

func GetCurrentProjectPath() string

func GetExt

func GetExt(fileName string) string

GetExt 获取文件后缀

func GetFileMode

func GetFileMode(num int) os.FileMode

perm :文件权限,一个八进制数。r(读)04,w(写)02,x(执行)01。

func GetFileSize

func GetFileSize(filename string) (int64, error)

获取文件大小

func GetFileSizeByFormat

func GetFileSizeByFormat(filename string) (string, error)

func GetFiles

func GetFiles(path string, filter func(name string, isDir bool) bool, option GetFilesOption) ([]string, error)

func GetImgType

func GetImgType(p string) (string, error)

GetImgType 获取Img文件类型

func GetName

func GetName(filePath string) string

func GetPrePath

func GetPrePath(ps string) string

ps must is the full path name

func GetSize

func GetSize(f multipart.File) (int, error)

GetSize 获取文件大小

func GetSubDirs

func GetSubDirs(path string, filter func(name string) bool) ([]string, error)

func GetTmpDir

func GetTmpDir() string

获取系统临时目录,兼容go run

func GetType

func GetType(p string) (string, error)

GetType 获取文件类型

func IsNotExistMkDir

func IsNotExistMkDir(src string) error

IsNotExistMkDir 检查文件夹是否存在 如果不存在则新建文件夹

func Join

func Join(str ...string) string

func LastPathName

func LastPathName(fp string) string

func MkDir

func MkDir(src string) error

MkDir 新建文件夹

func MkDirByMode

func MkDirByMode(src string, model os.FileMode) error

*

if err := fileUtil.MkDirByMode(file, 0700); err != nil {
		return gm.FailureResultWithError[string](500, fmt.Errorf("Could not create directory %s", file))
}

func MoveFile

func MoveFile(source, target string)

func Open

func Open(name string, flag int, perm os.FileMode) (*os.File, error)

Open 打开文件

func ReadFile

func ReadFile(filePath string) (string, error)

func ReplaceStr

func ReplaceStr(src, dst string, rmap map[string]string) error

func Walk

func Walk(basePath string, filer func(name string, isDir bool) bool, option GetFilesOption) ([]string, error)

func WalkDir

func WalkDir(basePath string, filer func(name string) bool, option GetFilesOption) ([]string, error)

WalkDir 获取符合条件的子目录 TODO: 当碰到已符合条件的目录后,是否继续查这个目录下的子目录? 这个还未实现

func WriteFile

func WriteFile(filePath string, content string) (re error)

func WriteFileByBytes

func WriteFileByBytes(content bytes.Buffer, name string)

func WriteFileByMode

func WriteFileByMode(nameWithPath string, data []byte, perm os.FileMode) error

Types

type GetFilesOption

type GetFilesOption struct {
	// contains filtered or unexported fields
}

func NewGetFilesOption

func NewGetFilesOption() GetFilesOption

Jump to

Keyboard shortcuts

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