fsx

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 8, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CleanFileName

func CleanFileName(name string) string

CleanFileName 清理文件名,移除非法字符、控制字符、下划线、连续空白字符、连续点号、下划线前后的多余空格

可选参数 keepHeadDot:是否保留首尾的点号(默认保留)
返回清理后的文件名, 如果文件名为空, 则返回空字符串

func CreateDir

func CreateDir(path string) error

CreateDir 创建目录,如果路径存在且是零文件,尝试删除后再创建

func DirIsEmpty

func DirIsEmpty(path string) (bool, error)

func Eon

func Eon[V, E any](_ V, e E) E

func Fcp

func Fcp(srcPath, dstPath string) error

func FileCheck

func FileCheck(target string) (skipExist bool, err error)

FileCheck 存在是非空文件:跳过,存在空文件:删除,不存在:正常返回,打开出错:报错

func FileExist

func FileExist(path string) error

func From

func From(src *os.File) func(dst *os.File) error

func ListFiles

func ListFiles(sources []string, recursive bool, onError func(error) error) (files []string, err error)

ListFiles 遍历 sources 中的路径,返回文件列表 sources: 需要遍历的文件或目录路径列表 recursive: 是否递归遍历子目录 onError: 错误处理回调函数,当遇到无法访问的路径时触发

func NotExist

func NotExist(path string) error

func Open

func Open(path string, process func(r *os.File) error, options ...FileOpenOption) error

func RenameFile

func RenameFile(from, to string) error

RenameFile 单个文件重命名,自动覆盖目标(如果目标存在且为单文件或者空文件夹)

func Split

func Split(path string) (dir, name, ext string)

func To

func To(dst *os.File) func(src *os.File) error

func UseTempFile

func UseTempFile(dstPath string, process func(tempFile *os.File) error) (err error)

func Von

func Von[V, E any](v V, _ E) V

func WriteToFile

func WriteToFile(dstPath string) func(src *os.File) error

Types

type FileOpenOption

type FileOpenOption func(*FileOpenOptions)

func Flag

func Flag(flag int) FileOpenOption

func Writeable

func Writeable(appendFlag ...int) FileOpenOption

type FileOpenOptions

type FileOpenOptions struct {
	Flag int
	Perm os.FileMode
}

type SortFunc

type SortFunc func(a, b string) int

func ByLength

func ByLength(reverse bool) SortFunc

ByLength 排序规则:路径长度降序(深层在前),长度相同时按字典序升序

func ByName

func ByName(reverse bool) SortFunc

func Sorts

func Sorts(sorts ...SortFunc) SortFunc

Jump to

Keyboard shortcuts

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