fileutil

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2023 License: MIT Imports: 18 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Abs

func Abs(path string) (string, error)

Abs get file absolute path

func Basename

func Basename(path string) string

Basename get filename

func CleanPath

func CleanPath(p string) string

func CopyFile

func CopyFile(srcPath string, dstPath string) error

CopyFile copy src file to dest file.

func CurrentPath

func CurrentPath() string

CurrentPath return current absolute path.

func Delete added in v0.1.5

func Delete(path string, tier int) error

Delete 删除文件并删除{tier}层空文件夹

func Dirname

func Dirname(path string) string

Dirname get file dir name

func ExecPath

func ExecPath() string

ExecPath get the program`s directory

func Exist

func Exist(path string) bool

Exist judge whether exists filepath

func FileMode

func FileMode(path string) (fs.FileMode, error)

FileMode return file's mode and permission.

func FileSize

func FileSize(path string) int64

FileSize obtain file size

func FilenameNoExt

func FilenameNoExt(filename string) string

FilenameNoExt get the filename without subfix

func Format

func Format(path string) string

Format the path

func GenUniqueFilename

func GenUniqueFilename(filename string, tries int, callback func(name string) string) (string, error)

GenUniqueFilename gen a unique filename

func IsDir

func IsDir(path string) bool

IsDir judge whether is a dir

func IsFile

func IsFile(path string) bool

IsFile judge whether is a file

func IsLink(path string) bool

IsLink checks if a file is symbol link or not.

func IsZipFile

func IsZipFile(filepath string) bool

IsZipFile checks if file is zip or not.

func Join

func Join(elem ...string) string

Join the path

func ListFiles

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

ListFiles return all file names in the path.

func MTime

func MTime(filepath string) (int64, error)

MTime returns file modified time.

func MiMeType

func MiMeType(file any) string

MiMeType return file mime type param `file` should be string(file path) or *os.File.

func Mkdir

func Mkdir(path string) error

Mkdir create a folder

func MkdirP

func MkdirP(path string) error

MkdirP create a path's parents dir

func Move

func Move(src, dst string) error

Move a file from `src` to `dst`

func Pwd

func Pwd() string

Pwd get work path

func ReadByLine

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

ReadByLine read file line by line.

func ReadCsvFile

func ReadCsvFile(filepath string) ([][]string, error)

ReadCsvFile read file content into slice.

func ReadToString

func ReadToString(path string) (string, error)

ReadToString return string of file content.

func Relvate

func Relvate(basepath, targpath string) (string, error)

Relvate get the relvative path of `targpath` to `basepath`

func Rm

func Rm(path string) error

Rm remove a file

func Rmf

func Rmf(path string) error

Rmf rm -f file or folder

func Sha

func Sha(filepath string, shaType ...int) (string, error)

Sha returns file sha value, param `shaType` should be 1, 256 or 512.

func Split

func Split(path string) (string, string)

Split get file dir name

func Suffix

func Suffix(path string) string

Suffix get file suffix

func UnZip

func UnZip(zipFile string, destPath string) error

UnZip unzip the file and save it to destPath.

func WriteBytesToFile

func WriteBytesToFile(filepath string, content []byte) error

WriteBytesToFile write bytes to target file.

func WriteCsvFile

func WriteCsvFile(filepath string, records [][]string, append bool) error

WriteCsvFile write content to target csv file.

func WriteStringToFile

func WriteStringToFile(filepath string, content string, append bool) error

WriteStringToFile write string to target file.

func Zip

func Zip(fpath string, destPath string) error

Zip create zip file, fpath could be a single file or a directory.

func ZipAppendEntry

func ZipAppendEntry(fpath string, destPath string) error

ZipAppendEntry append a single file or directory by fpath to an existing zip file.

Types

This section is empty.

Jump to

Keyboard shortcuts

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