fileutil

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CopyAllContent added in v0.10.0

func CopyAllContent(srcDir string, dstDir string) error

CopyAllContent copies all files from srcDir to dstDir recursively. Only files' name and content are guaranteed to be the same. Only files are copied, (empty) directories are ignored. Any existing files will be overridden.

func CopyContent added in v0.10.0

func CopyContent(src string, dst string) error

CopyContent copies the file src to dst. Only the file's name and content are guaranteed to be the same. The parents will be created if they don't exist. The existing file will be overridden.

func Exists added in v0.7.0

func Exists(path string) (bool, error)

Exists checks if the file or directory exists. If Exists cannot determinate whether the file or directory exists (e.g., permission error), it returns an error.

func ListAll added in v0.10.0

func ListAll(dirPath string) ([]string, error)

ListAll lists all files and directories under the directory dirPath.

func ListAllFiles added in v0.10.0

func ListAllFiles(dirPath string) ([]string, error)

ListAllFiles lists all files under the directory dirPath.

func Lowercase added in v0.10.0

func Lowercase(path string) error

Lowercase renames the file or directory to lowercase. If the file or directory is already lower-cased, it does nothing.

func LowercaseAll

func LowercaseAll(dirPath string) error

LowercaseAll renames the directory to lowercase recursively. If a file or directory is already lower-cased, LowercaseAll does nothing to it.

func MkFile added in v0.10.0

func MkFile(filePath string) (*os.File, error)

MkFile creates a file and its parents with respectively mode 0666 and 0755 (both before unmask). If the parents of the file already exist, MkFile does nothing. If the file already exist, MkFile truncates it.

func MkFileFromBytes added in v0.10.0

func MkFileFromBytes(filePath string, b []byte) error

MkFileFromBytes calls MkFile and then writes the content of the bytes to the file.

func MkFileFromReader added in v0.10.0

func MkFileFromReader(filePath string, r io.Reader) error

MkFileFromReader calls MkFile and then writes the content of the reader to the file.

Note that it's the caller's responsibility to close the reader.

func MkParents added in v0.10.0

func MkParents(filePath string) error

MkParents creates all parents of a file with mode 0755 (before unmask). If the parents of the file already exist, MkParents does nothing.

func MoveAllContent added in v0.10.0

func MoveAllContent(srcDir string, dstDir string) error

MoveAllContent moves all files from srcDir to dstDir recursively. Only files' name and content are guaranteed to be the same. Only files are moved, (empty) directories are ignored. Any existing files will be overridden.

Use MoveAllContent to prevent os.Rename to panic "invalid cross-device link".

func MoveContent added in v0.10.0

func MoveContent(src string, dst string) error

MoveContent moves the file src to dst. Only the file's name and content are guaranteed to be the same. The parents will be created if they don't exist. The existing file will be overridden.

Types

This section is empty.

Jump to

Keyboard shortcuts

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