fileutil

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2023 License: MIT Imports: 18 Imported by: 123

Documentation

Overview

Package fileutil implements some basic functions for file operations

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClearFile added in v1.0.6

func ClearFile(path string) error

ClearFile write empty string to path file

func CopyFile

func CopyFile(srcFilePath string, dstFilePath string) error

CopyFile copy src file to dest file

func CreateDir added in v1.3.0

func CreateDir(absPath string) error

CreateDir create directory in absolute path. param `absPath` like /a/, /a/b/

func CreateFile

func CreateFile(path string) bool

CreateFile create a file in path

func CurrentPath added in v1.3.8

func CurrentPath() string

CurrentPath return current absolute path.

func FileMode added in v1.1.8

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

FileMode return file's mode and permission

func FileSize added in v1.3.8

func FileSize(path string) (int64, error)

FileSize returns file size in bytes.

func IsDir

func IsDir(path string) bool

IsDir checks if the path is directory or not

func IsExist

func IsExist(path string) bool

IsExist checks if a file or directory exists

func IsLink(path string) bool

IsLink checks if a file is symbol link or not

func IsZipFile added in v1.3.8

func IsZipFile(filepath string) bool

IsZipFile checks if file is zip or not.

func ListFileNames

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

ListFileNames return all file names in the path

func MTime added in v1.3.8

func MTime(filepath string) (int64, error)

MTime returns file modified time.

func MiMeType added in v1.1.8

func MiMeType(file interface{}) string

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

func ReadCsvFile added in v1.3.8

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

ReadCsvFile read file content into slice.

func ReadFileByLine added in v1.0.6

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

ReadFileByLine read file line by line

func ReadFileToString added in v1.0.6

func ReadFileToString(path string) (string, error)

ReadFileToString return string of file content

func RemoveFile

func RemoveFile(path string) error

RemoveFile remove the path file

func Sha added in v1.3.8

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

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

func UnZip added in v1.1.8

func UnZip(zipFile string, destPath string) error

UnZip unzip the file and save it to destPath

func WriteBytesToFile added in v1.3.9

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

WriteBytesToFile write bytes to target file.

func WriteCsvFile added in v1.4.0

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

WriteCsvFile write content to target csv file.

func WriteStringToFile added in v1.3.9

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

WriteStringToFile write string to target file.

func Zip added in v1.1.8

func Zip(fpath string, destPath string) error

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

func ZipAppendEntry added in v1.4.0

func ZipAppendEntry(fpath string, destPath string) error

ZipAppendEntry append a single file or directory by fpath to an existing zip file. Play: https://go.dev/play/p/cxvaT8TRNQp

Types

This section is empty.

Jump to

Keyboard shortcuts

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