fileutil

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CloseIfIsCloser added in v0.11.0

func CloseIfIsCloser(r any) error

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 List added in v0.11.0

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

List lists all files and directories under the directory dirPath (no recursive).

func ListALlDirs added in v0.11.0

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

ListALlDirs lists all directories under the directory dirPath (recursive).

func ListAll added in v0.10.0

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

ListAll lists all files and directories under the directory dirPath (recursive).

func ListAllFiles added in v0.10.0

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

ListAllFiles lists all files under the directory dirPath (recursive).

func ListDirs added in v0.11.0

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

ListDirs lists all directories under the directory dirPath (no recursive).

func ListFiles added in v0.11.0

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

ListFiles lists all files under the directory dirPath (no recursive).

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.

If the reader implements io.Closer, it would be closed when the method returns.

func MkFilesFromBytes added in v1.0.0

func MkFilesFromBytes(goroutines int, s ...PathWithContent) error

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

type PathWithContent added in v1.0.0

type PathWithContent struct {
	FilePath string
	Content  []byte
}

Jump to

Keyboard shortcuts

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