file

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const PathSeparatorStr = string(os.PathSeparator)

Variables

This section is empty.

Functions

func Copy

func Copy(srcFile, dstFile string) error

Copy 复制文件或目录。如果目标路径不存在,会自动创建对应目录。 参数:

  • srcFile: 源文件或目录路径。
  • dstFile: 目标文件或目录路径。

返回值:

  • error: 错误信息。

func GetSystemRootDir

func GetSystemRootDir() string

GetSystemRootDir 返回操作系统安装位置的根目录 Windows: C:\ (基于 SystemDrive/SystemRoot 环境变量) Unix: /

func Mov

func Mov(srcFile, dstFile string) error

Mov 移动文件或目录。如果目标路径已存在,会覆盖目标文件或目录。 参数:

  • srcFile: 源文件或目录路径。
  • dstFile: 目标文件或目录路径。

返回值:

  • error: 错误信息。

func PathExists

func PathExists(path string) (bool, error)

PathExists 检查指定路径是否存在。 参数:

  • path: 需要检查的文件或目录路径。

返回值:

  • bool: 如果路径存在,返回 true;否则返回 false。
  • error: 如果检查过程中发生错误(非“路径不存在”错误),返回该错误;否则返回 nil。

注意:

  • 如果路径不存在,不会返回错误,而是返回 false 和 nil。
  • 其他错误(如权限不足)会直接返回。

func ReadFileLines

func ReadFileLines(path string, delim byte) []string

ReadFileLines 读取文件内容并按指定分隔符分割为多行字符串。

参数:

  • path: 文件路径。
  • delim: 行分隔符。

返回值:

  • []string: 分割后的字符串数组。

func ReadFileLinesTrimDelim

func ReadFileLinesTrimDelim(path string, delim byte, isTrim bool) []string

ReadFileLinesTrimDelim 读取指定路径的文件并按分隔符分割为行数组

参数:

  • path: 文件路径
  • delim: 行分隔符
  • isTrim: 是否去除每行两端的空白字符

返回值:

  • []string: 字符串数组,包含文件中的各行内容

注意:

如果文件不存在或无法访问,返回空数组
遇到IO错误时会panic

Types

This section is empty.

Jump to

Keyboard shortcuts

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