fs

package
v1.9.2 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2026 License: MIT, Apache-2.0 Imports: 22 Imported by: 10

Documentation

Index

Constants

View Source
const (
	Cover mode = iota
	SameNameSkip
	SameNameAndMd5Skip
)
View Source
const (
	ModeDir  = 0755
	ModeFile = 0644
)
View Source
const DownloadKey = ".downloading"
View Source
const PathSeparator = string(os.PathSeparator)

Variables

View Source
var FileTypeMap = map[string]FileType{
	".txt": Txt,
	".doc": Doc,
}

Functions

func All

func All(path string) (iter.Seq[os.DirEntry], error)

func Copy

func Copy(dst, src string) error

func CopyByMode

func CopyByMode(dst, src string, c mode) error

func CopyDir

func CopyDir(dst, src string) error

CopyDir 递归复制目录

func CopyDirByMode

func CopyDirByMode(dst, src string, c mode) error

CopyDirByMode 递归复制目录

func Create

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

func CreateTime

func CreateTime(path string) time.Time

func CreateTimeByEntry

func CreateTimeByEntry(entry os.DirEntry) time.Time

func CreateTimeByInfo

func CreateTimeByInfo(fileInfo os.FileInfo) time.Time

func DirsDeDuplicate

func DirsDeDuplicate(dirs ...string) error

去除目录中重复的文件,默认保留参数靠前目录中的文件

func DirsDuplicateHandle

func DirsDuplicateHandle(callback func(path1, path2 string) error, dirs ...string) error

func DirsRangeDuplicateHandle

func DirsRangeDuplicateHandle(rangeCallback func(dir string, entry os.DirEntry) (error, bool), duplicateCallback func(path1, path2 string) error, dirs ...string) error

DirsRangeDuplicateHandle rangeCallback 返回值为错误和是否继续

func Download

func Download(filepath string, reader io.Reader) error

func DownloadByMode

func DownloadByMode(filepath string, reader io.Reader, c mode) error

func Exist

func Exist(filepath string) bool

func Find

func Find(src, dst string) (string, error)

path和filepath两个包,filepath文件专用

func FindFiles

func FindFiles(src, dst string, deep int8, num int) ([]string, error)

func FindFilesParallel added in v1.7.6

func FindFilesParallel(src, dst string, deep int8, num int) ([]string, error)

path和filepath两个包,filepath文件专用

func GetMd5Name

func GetMd5Name(name string) string

func IsExist

func IsExist(src string) bool

func IsNotExist

func IsNotExist(src string) bool

func IsPermission

func IsPermission(src string) bool

func LastFile

func LastFile(dir string) (os.FileInfo, map[string]os.FileInfo, error)

LastFile 当前目录最后一个创建的文件

func Md5

func Md5(path string) (string, error)

func Md5Equal

func Md5Equal(path1, path2 string) (bool, error)

func Mkdir

func Mkdir(src string) error

func MkdirAll

func MkdirAll(src string) error

func Move

func Move(src, dst string) error

func MoveDirByMode

func MoveDirByMode(src, dst string, c mode) error

func MustOpen

func MustOpen(filePath string) (*os.File, error)

func NotExist

func NotExist(filepath string) bool

func Open

func Open(filepath string) (*os.File, error)

func OpenFile

func OpenFile(path string, flag int, perm os.FileMode) (*os.File, error)

func Sync

func Sync(slaveDir, mainDir string) error

两个目录同步,第一个参数为主目录,参考目录,第二个参数目录与第一个保持一致

func TwoDirDeDuplicate

func TwoDirDeDuplicate(dir1, dir2 string) error

去除两个目录中重复的文件,默认保留第一个目录中的文件

func TwoDirDuplicateHandle

func TwoDirDuplicateHandle(dir1, dir2 string, callback func(path1, path2 string) error) error

func Walk

func Walk(dir string, callback WalkCallback) error

遍历WalkCallback文件调用callback,包括文件夹,与filepath.WalkDir不同的是回调函数的参数不同,filepath.WalkDir的第一个参数是文件完整路径,WalkFile是文件所在目录的路径

func WalkDir

func WalkDir(dir string, callback func(dir string, entries []os.DirEntry) ([]os.DirEntry, error)) error

WalkDir 遍历根目录中的每个文件夹,为文件夹中所有文件和目录的切片(os.ReadDir的返回)调用callback callback 需要处理每个文件夹下的所有文件和目录,返回值为需要递归遍历的目录和error 几乎每个文件夹下的文件夹都会被循环两次!

func WalkFile added in v1.8.1

func WalkFile(dir string, callback WalkCallback) error

遍历根目录中的每个文件,为每个文件调用callback,不包括文件夹,与filepath.WalkDir不同的是回调函数的参数不同,filepath.WalkDir的第一个参数是文件完整路径,WalkFile是文件所在目录的路径

func WriteFile added in v1.8.1

func WriteFile(filepath string, reader io.Reader) (int64, error)

Types

type Dir

type Dir string

func (Dir) Open

func (d Dir) Open(name string) (*os.File, error)

type FileSize

type FileSize int64

func (FileSize) MarshalText

func (f FileSize) MarshalText() ([]byte, error)

MarshalText

func (*FileSize) UnmarshalText

func (f *FileSize) UnmarshalText(text []byte) error

UnMarshalText

type FileType

type FileType int
const (
	Unknown FileType = iota
	Txt
	Doc
	Docx
	Xls
	Xlsx
)

type WalkCallback added in v1.8.1

type WalkCallback = func(dir string, entry os.DirEntry) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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