file

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 22, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AtomicWriteFile

func AtomicWriteFile(filepath string, data []byte, perm os.FileMode) (err error)

func CleanDir

func CleanDir(dir string)

CleanDir removes the directory.

func CleanDirs

func CleanDirs(dirs ...string)

CleanDirs removes multiple directories.

func CleanFile

func CleanFile(file *os.File)

CleanFile removes the file.

func CleanFiles

func CleanFiles(file ...string) error

CleanFiles removes multiple files.

func Copy

func Copy(src, dest string) error

Copy copies file from source to target path.

func CopyDirV3

func CopyDirV3(srcPath, destPath string, filters ...func(filePath string) bool) error

CopyDirV3 copy files recursively from source to target directory.

The filter accepts a function that process the path info. and should return true for need to filter.

It returns error when error occurs in underlying functions.

func CountDirFiles

func CountDirFiles(dirName string) int

CountDirFiles reutrns # of files under a directory.

func Filename

func Filename(f string) string

Filename returns the file name after the last "/".

func GetAllSubDirs

func GetAllSubDirs(rootPath string) ([]string, error)

GetAllSubDirs returns all subdirectories of given root path. Slice does not include given path itself.

func GetFileListBySuffix

func GetFileListBySuffix(dirPath, suffix string) ([]string, error)

GetFileListBySuffix returns an ordered list of file paths. It recognize if given path is a file, and don't do recursive find.

func GetFileSize

func GetFileSize(path string) (size int64, err error)

GetFileSize returns the size of a file.

func GetFiles

func GetFiles(path string) (paths []string, err error)

GetFiles returns all the files under the path.

func GetFilesSize

func GetFilesSize(paths []string) (int64, error)

GetFilesSize returns the size of multiple files.

func GetHomeDir

func GetHomeDir() string

func IsDir

func IsDir(path string) bool

IsDir returns if the given path is a directory.

func IsExist

func IsExist(fileName string) bool

IsExist returns if a file exists.

func IsFile

func IsFile(filePath string) bool

IsFile returns true if given path is a file, or returns false when it's a directory or does not exist.

func LgetAllSubDirs

func LgetAllSubDirs(rootPath string) ([]string, error)

LgetAllSubDirs returns all subdirectories of given root path, including following symbolic links, if any. Slice does not include given path itself.

func LstatDir

func LstatDir(rootPath string, includeDir ...bool) ([]string, error)

LstatDir gathers information of given directory by depth-first. It returns slice of file list, follows symbolic links and includes subdirectories if enabled; it returns error and nil slice when error occurs in underlying functions, or given path is not a directory or does not exist.

Slice does not include given path itself. If subdirectories is enabled, they will have suffix '/'.

func MkDirs

func MkDirs(dirs ...string) error

MkDirs creates directories.

func MkTmpFile

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

MkTmpFile creates a temporary file.

func MkTmpdir

func MkTmpdir(dir string) (string, error)

MkTmpdir creates a temporary directory.

func ReadAll

func ReadAll(fileName string) ([]byte, error)

ReadAll reads all the content of the file.

func ReadLines

func ReadLines(fileName string) ([]string, error)

ReadLines reads the contents from the file line by line.

func RecursionCopy

func RecursionCopy(src, dst string) error

RecursionCopy equals to `cp -r`

func StatDir

func StatDir(rootPath string, includeDir ...bool) ([]string, error)

StatDir gathers information of given directory by depth-first. It returns slice of file list and includes subdirectories if enabled; it returns error and nil slice when error occurs in underlying functions, or given path is not a directory or does not exist.

Slice does not include given path itself. If subdirectories is enabled, they will have suffix '/'.

func WriteFile

func WriteFile(fileName string, content []byte) error

WriteFile outputs all content to the file.

func WriteLines

func WriteLines(fileName string, lines []string) error

WriteLines outputs lines to the file.

Types

This section is empty.

Jump to

Keyboard shortcuts

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