file

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2025 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrWantDirGotFile = errors.New("expected directory, but found file")
	ErrWantFileGotDir = errors.New("expected file, but found directory")
)

Functions

func AppendToFile

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

AppendToFile 追加内容到指定文件。

如果文件存在,则追加内容;如果文件不存在,则创建新文件并写入内容。

参数:

  • filepath: 文件的路径
  • content: 需要追加的字节内容

返回值:

  • err: 如果写入失败,返回错误信息;否则返回 nil。

func AppendToFileString

func AppendToFileString(filepath, content string) (err error)

AppendToFileString 追加内容到指定文件。

如果文件存在,则追加内容;如果文件不存在,则创建新文件并写入内容。

func DirExists

func DirExists(path string) (exist bool, err error)

func FileExists

func FileExists(path string) (exist bool, err error)

func IsDirEmpty

func IsDirEmpty(dir string) (empty bool, err error)

IsDirEmpty 检查目录是否为空

func MkdirAll

func MkdirAll(dir string) (err error)

func ReadFile

func ReadFile(filepath string) (content string, err error)

func RemoveDir

func RemoveDir(dirPath string) (err error)

func RemoveFile

func RemoveFile(filePath string) (err error)

func WriteFile

func WriteFile(filepath string, content []byte) (err error)

WriteFile 写入内容到指定文件。

如果文件已存在,则覆盖原文件内容。

如果文件不存在,则创建新文件并写入内容。

参数:

  • filepath: 文件的路径
  • content: 需要写入的字节内容

返回值:

  • err: 如果写入失败,返回错误信息;否则返回 nil。

func WriteFileString

func WriteFileString(filepath, content string) (err error)

WriteFileString 写入内容到指定文件。

如果文件已存在,则覆盖原文件内容。

如果文件不存在,则创建新文件并写入内容。

Types

This section is empty.

Jump to

Keyboard shortcuts

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