Documentation
¶
Overview ¶
XFile 提供了一组实用的文件系统操作工具函数,支持文件读写和路径处理等功能。
功能特性
- 文件操作:支持文件的常用操作,如:检查、读取、写入、删除等
- 目录操作:支持目录的常用操作,如:检查、创建、获取目录名称等
- 路径处理:统一的 POSIX 风格路径处理,支持路径拼接及标准化
使用手册
1. 文件操作
1.1 文件检查
exists := XFile.HasFile("path/to/file.txt")
1.2 文件读写
data := XFile.OpenFile("config.dat")
err := XFile.SaveFile("config.dat", data, 0644)
text := XFile.OpenText("config.txt")
err := XFile.SaveText("config.txt", "Hello World", 0644)
2. 目录操作
2.1 目录管理
exists := XFile.HasDirectory("path/to/dir")
success := XFile.CreateDirectory("path/to/dir")
parent := XFile.DirectoryName("path/to/file.txt")
3. 路径处理
3.1 路径操作
path := XFile.PathJoin("path", "to", "file.txt")
norm := XFile.NormalizePath("path/./to/../file.txt")
更多信息请参考模块文档。
Index ¶
- Constants
- func CreateDirectory(path string) bool
- func DeleteFile(file string) bool
- func DirectoryName(path string) string
- func HasDirectory(dir string, createIsNotExist ...bool) bool
- func HasFile(file string) bool
- func NormalizePath(path string) string
- func OpenFile(file string) []byte
- func OpenText(file string) string
- func PathJoin(paths ...string) string
- func SaveFile(file string, data []byte, perm ...os.FileMode) error
- func SaveText(file string, data string, perm ...os.FileMode) error
Constants ¶
View Source
const Separator string = "/"
Separator 是路径分隔符(POSIX风格)。
Variables ¶
This section is empty.
Functions ¶
func CreateDirectory ¶
CreateDirectory 在指定路径创建一个文件夹。 如果文件夹已经存在,则不执行任何操作并返回 true。 返回 true 表示创建成功或目录已存在,false 表示创建失败。
func DeleteFile ¶
DeleteFile 删除指定的文件。 返回 true 表示删除成功,false 表示删除失败。
func HasDirectory ¶
HasDirectory 检查文件夹是否存在。 createIsNotExist 为 true 时,如果目录不存在则创建。 返回 true 表示目录存在或创建成功,false 表示目录不存在或创建失败。
func NormalizePath ¶
NormalizePath 标准化路径字符串。 处理特殊前缀(file://、jar:file://)。 统一使用 POSIX 风格的路径分隔符。 处理 . 和 .. 路径片段。 返回标准化后的路径。
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.