filex

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Byte         int64 = 1
	Kilobyte           = 1024 * Byte
	Megabyte           = 1024 * Kilobyte
	Gigabyte           = 1024 * Megabyte
	Trillionbyte       = 1024 * Gigabyte
	Petabyte           = 1024 * Trillionbyte
	Exabyte            = 1024 * Petabyte
)

Variables

View Source
var IsDirectory = IsDir

IsDirectory reports whether the named file is a directory.

View Source
var (
	// PathSeparator can be used to override the operating system separator.
	PathSeparator = string(os.PathSeparator)
)

Functions

func CopyFile

func CopyFile(src, dst string, isFirstDel ...bool) (err error)

CopyFile 复制文件

func Create

func Create(path string) (*os.File, error)

Create 可以新建文件/目录 注: 需要外部调用 Close 进行关闭

func GetSize

func GetSize(path string) (int64, error)

GetSize 获取文件大小

func HumanReadableSize

func HumanReadableSize(size int64) string

func IsDir

func IsDir(filepath string) bool

IsDir reports whether the named file is a directory.

func IsExist

func IsExist(filepath string) bool

IsExist returns a boolean indicating whether a file or directory exist.

func IsNotExist

func IsNotExist(filepath string) bool

IsNotExist returns a boolean indicating whether a file or directory not exist.

Types

type FileTree

type FileTree map[string]FileTree

FileTree represents a directory in a filesystem-tree structure.

func (FileTree) AddDir

func (tree FileTree) AddDir(path string) error

AddDir adds a directory to a FileTree. If the path includes subdirectories they are created as necessary.

func (FileTree) AddFile

func (tree FileTree) AddFile(path string) error

AddFile adds a file to a FileTree. If the path includes subdirectories they are created as necessary.

func (FileTree) At

func (tree FileTree) At(path string) (FileTree, error)

At returns a new FileTree rooted at the given path.

func (FileTree) Remove

func (tree FileTree) Remove(path string) error

Remove an entry from a FileTree.

func (FileTree) Visit

func (tree FileTree) Visit(path string, order VisitOrder, fn VisitFunc) error

Visit calls the callback function for the given path and recursively all its contents, if a directory path is passed.

type VisitFunc

type VisitFunc func(path string, isDir bool) error

VisitFunc is the type for a callback to visit the entries on a directory and its subdirectories.

type VisitOrder

type VisitOrder int8

VisitOrder is a two-valued flag used to control how directories are visited.

const (
	// PreOrder has directories visited before their contents.
	PreOrder VisitOrder = iota
	// PostOrder has directories visited after their contents.
	PostOrder
)

Jump to

Keyboard shortcuts

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