fs

package
v1.2.8 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: MIT Imports: 21 Imported by: 0

Documentation

Overview

inspiring from https://www.youtube.com/watch?v=1B71SL6Y0kA

Index

Constants

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 Check

func Check(src string) error

func CheckExist

func CheckExist(src string) bool

func CheckNotExist

func CheckNotExist(src string) bool

func CheckPermission

func CheckPermission(src string) bool

func CopyDir

func CopyDir(src, dst string) error

CopyDir 递归复制目录

func CopyFile

func CopyFile(src, dst string) error

CopyFile : General Approach

func CreatFileFromReader

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

func CreatFileFromReaderIfNotExists

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

func Create

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

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 Exist

func Exist(filepath string) bool

func FindFile

func FindFile(path string) (string, error)

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

func FindFiles

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

func FindFiles2

func FindFiles2(path string, deep int8, num int) ([]string, error)

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

func GetFileCreateTime

func GetFileCreateTime(path string) int64

func GetLogFilePath

func GetLogFilePath(RuntimeRootPath, LogSavePath string) string

func GetMd5Name

func GetMd5Name(name string) string

func Inspect

func Inspect(dir string, file func(string, os.DirEntry) bool) error

Inspect

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 MustOpen

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

func NotExist

func NotExist(filepath string) bool

func Open

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

func OpenLogFile

func OpenLogFile(fileName, filePath string) (*os.File, error)

func Range

func Range(dir string, callback FileRangeCallback) error

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

func RangeDir

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

RangeDir 遍历根目录中的每个文件夹,为文件夹调用callback callback 返回值为需要递归遍历的目录和error 几乎每个文件夹下的文件夹都会被循环两次!

func RangeFile

func RangeFile(dir string, callback FileRangeCallback) error

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

func SafeCopyFile

func SafeCopyFile(src, dst string) error

SafeCopyFile : Error handling by abstraction

func Sync

func Sync(mainDir, slaveDir 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(root string, fn filepath.WalkFunc) error

func WalkDir

func WalkDir(root string, fn fs.WalkDirFunc) error

func WalkDirWithFS

func WalkDirWithFS(fsys fs.FS, root string, fn fs.WalkDirFunc) error

func Write

func Write(data []byte, filename string) (n int, err error)

func WriteBuffer

func WriteBuffer(buf *bytes.Buffer, filename string) (n int, err error)

Types

type Dir

type Dir string

func (Dir) Open

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

type DirEntries

type DirEntries []os.DirEntry

func (DirEntries) Len

func (e DirEntries) Len() int

func (DirEntries) Less

func (e DirEntries) Less(i, j int) bool

func (DirEntries) Swap

func (e DirEntries) Swap(i, j int)

type FileRangeCallback

type FileRangeCallback = func(dir string, entry os.DirEntry) 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 SafeCopy

type SafeCopy struct {
	// contains filtered or unexported fields
}

func (*SafeCopy) Close

func (c *SafeCopy) Close()

func (*SafeCopy) Copy

func (c *SafeCopy) Copy()

func (*SafeCopy) Create

func (c *SafeCopy) Create(dst string)

type Visitor

type Visitor interface {
	Visit(dir string, file os.DirEntry) (w Visitor)
}

Directories

Path Synopsis
watch

Jump to

Keyboard shortcuts

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