file

package
v0.41.8 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2020 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BaseName

func BaseName(path string) string

BaseName 获取文件名,不带后缀 eg: BaseName("/tmp/test.txt") -> test

func DirContains added in v0.39.8

func DirContains(dirname string, name string) bool

DirContains 文件夹下是否包含指定名称的文件或者文件夹

func ExtensionName

func ExtensionName(path string) string

ExtensionName 获取文件拓展名 eg: ExtensionName("/tmp/test.txt") -> .txt

func IsDir

func IsDir(path string) bool

IsDir 判断路径是否是文件夹 eg:

/tmp 为实际上存在的文件夹 IsDir("/tmp") -> true

/tmp2 为实际上不存在的文件夹 IsDir("/tmp2") -> false

/tmp/test.txt 为实际存在的文件 IsDir("/tmp/test.txt") -> false

func IsExist

func IsExist(path string) bool

IsExist 判断路径上的 文件或文件夹 是否存在 eg:

/tmp 为实际存在的文件夹 IsExist("/tmp") -> true

/tmp/test.txt 为实际存在的文件 IsExist("/tmp/test.txt") -> true

func IsFile

func IsFile(path string) bool

IsFile 判断路径是否是文件 eg:

/tmp 为实际存在的文件夹 IsFile("/tmp") -> false

/tmp/test.txt 为实际存在的文件 IsFile("/tmp/test.txt") -> true

/tmp/test2.txt 为实际不存在的文件 IsFile("/tmp/test2.txt") -> false

/tmp/test_link.txt 为有效的链接文件 ln -s src dst IsFile("/tmp/test_link.txt") -> true

func ListDirs added in v0.39.8

func ListDirs(dirname string) ([]string, error)

ListDirs 列出指定目录的文件夹

func Md5

func Md5(path string) (string, error)

Md5 计算文件 md5 值

func Name

func Name(path string) string

Name 获取文件名 eg: Name("/tmp/test.txt") -> test.txt

func NameRand

func NameRand(path string, sep ...string) string

NameRand 获取一个随机文件名称,默认以 _ 连接 eg: NameRand("test.txt") -> test_869mUEfWXOaB.txt eg: NameRand("test.txt", "@") -> test@jQ0EQkDQ285x.txt

func ReadLine

func ReadLine(path string, handle func([]byte) error) error

ReadLine 逐行读取文件、读取大文件 path: 文件路径 handle: 每读取一行的处理函数,返回的error为非nil时,不再继续向后读取

func Sha1

func Sha1(path string) (string, error)

Sha1 计算文件 sha1 值

func Sha256

func Sha256(path string) (string, error)

Sha256 计算文件 sha256 值

func Sha512

func Sha512(path string) (string, error)

Sha512 计算文件 sha512 值

func Size

func Size(path string) (int64, error)

Size 获取文件长度

Types

This section is empty.

Jump to

Keyboard shortcuts

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