Documentation ¶
Index ¶
- Constants
- Variables
- func CopyFile(src string, dst string) error
- func CreateFile(fpath string, filePerm, dirPerm os.FileMode) (*os.File, error)
- func DeleteIfExist(fpath string) error
- func DeleteIfFileExist(fpath string) error
- func Dir(fpath string) string
- func ExpandPath(path string) string
- func FileExists(path string) bool
- func FileExt(fpath string) string
- func IsAbsPath(aPath string) bool
- func IsDir(path string) bool
- func IsFile(path string) bool
- func IsImageFile(path string) bool
- func IsZipFile(filepath string) bool
- func MimeType(path string) (mime string)
- func MkParentDir(fpath string) error
- func Mkdir(dirPath string, perm os.FileMode) error
- func MustCopyFile(src string, dst string)
- func MustCreateFile(filePath string, filePerm, dirPerm os.FileMode) *os.File
- func MustReadFile(filePath string) []byte
- func MustRemove(fpath string)
- func Name(fpath string) string
- func OSTempDir(pattern string) (string, error)
- func OSTempFile(pattern string) (*os.File, error)
- func OpenFile(filepath string, flag int, perm os.FileMode) (*os.File, error)
- func PathExists(path string) bool
- func QuickOpenFile(filepath string) (*os.File, error)
- func QuietRemove(fpath string)
- func ReadExistFile(filePath string) []byte
- func ReadString(filename string) (string, error)
- func ReaderMimeType(r io.Reader) (mime string)
- func Realpath(path string) string
- func Suffix(fpath string) string
- func TempDir(dir, pattern string) (string, error)
- func TempFile(dir, pattern string) (*os.File, error)
- func Unzip(archive, targetDir string) (err error)
- type DirFilter
- type DirFilterFunc
- type FileFilter
- type FileFilterFunc
- func DotFileFilterFunc(include bool) FileFilterFunc
- func ExtFilterFunc(exts []string, include bool) FileFilterFunc
- func GlobFilterFunc(patterns []string, include bool) FileFilterFunc
- func ModTimeFilterFunc(limitSec int, op rune, include bool) FileFilterFunc
- func PathNameFilterFunc(names []string, include bool) FileFilterFunc
- func RegexFilterFunc(pattern string, include bool) FileFilterFunc
- func SuffixFilterFunc(suffixes []string, include bool) FileFilterFunc
- type FileFinder
- func (f *FileFinder) AddDir(dirPaths ...string) *FileFinder
- func (f *FileFinder) AddDirFilter(filterFuncs ...DirFilter) *FileFinder
- func (f *FileFinder) AddDirPath(dirPaths ...string) *FileFinder
- func (f *FileFinder) AddFile(filePaths ...string) *FileFinder
- func (f *FileFinder) AddFileFilter(filterFuncs ...FileFilter) *FileFinder
- func (f *FileFinder) AddFilePath(filePaths ...string) *FileFinder
- func (f *FileFinder) AddFilePaths(filePaths []string)
- func (f *FileFinder) AddFilter(filterFuncs ...interface{}) *FileFinder
- func (f *FileFinder) Each(fn func(filePath string))
- func (f *FileFinder) EachContents(fn func(contents, filePath string))
- func (f *FileFinder) EachFile(fn func(file *os.File))
- func (f *FileFinder) EachStat(fn func(fi os.FileInfo, filePath string))
- func (f *FileFinder) ExcludeDir(dirs ...string) *FileFinder
- func (f *FileFinder) ExcludeDotDir(exclude ...bool) *FileFinder
- func (f *FileFinder) ExcludeDotFile(exclude ...bool) *FileFinder
- func (f *FileFinder) ExcludeName(files ...string) *FileFinder
- func (f *FileFinder) Find() *FileFinder
- func (f *FileFinder) FindAll() []string
- func (f *FileFinder) NoDotDir(exclude ...bool) *FileFinder
- func (f *FileFinder) NoDotFile(exclude ...bool) *FileFinder
- func (f *FileFinder) Reset()
- func (f *FileFinder) String() string
- func (f *FileFinder) WithDirFilter(filterFuncs ...DirFilter) *FileFinder
- func (f *FileFinder) WithFileFilter(filterFuncs ...FileFilter) *FileFinder
- func (f *FileFinder) WithFilter(filterFuncs ...interface{}) *FileFinder
- type FileMeta
- type FilterFunc
- type FindResults
Constants ¶
const ( ExDotFile exDotFlag = 1 ExDotDir exDotFlag = 2 )
const (
// MimeSniffLen sniff Length, use for detect file mime type
MimeSniffLen = 512
)
Variables ¶
var ( // perm and flags for create log file DefaultDirPerm os.FileMode = 0775 DefaultFilePerm os.FileMode = 0665 DefaultFileFlags = os.O_CREATE | os.O_WRONLY | os.O_APPEND )
var ( DirExist = IsDir FileExist = IsFile PathExist = PathExists )
alias methods
var ( MustRm = MustRemove QuietRm = QuietRemove )
alias methods
var ImageMimeTypes = map[string]string{
"bmp": "image/bmp",
"gif": "image/gif",
"ief": "image/ief",
"jpg": "image/jpeg",
"jpeg": "image/jpeg",
"png": "image/png",
"svg": "image/svg+xml",
"ico": "image/x-icon",
"webp": "image/webp",
}
ImageMimeTypes refer net/http package
Functions ¶
func CreateFile ¶ added in v0.4.1
CreateFile create file if not exists Usage:
CreateFile("path/to/file.txt", 0664, 0666)
func DeleteIfExist ¶ added in v0.4.1
DeleteIfExist removes the named file or (empty) directory on exists.
func DeleteIfFileExist ¶ added in v0.4.1
DeleteIfFileExist removes the named file on exists.
func ExpandPath ¶ added in v0.4.1
ExpandPath will parse `~` as user home dir path.
func FileExists ¶
FileExists reports whether the named file or directory exists.
func IsImageFile ¶ added in v0.4.1
IsImageFile check file is image file.
func IsZipFile ¶
IsZipFile check is zip file. from https://blog.csdn.net/wangshubo1989/article/details/71743374
func MkParentDir ¶ added in v0.4.1
MkParentDir quick create parent dir
func MustCopyFile ¶ added in v0.4.1
MustCopyFile copy file to another path.
func MustCreateFile ¶ added in v0.4.1
MustCreateFile create file, will panic on error
func MustReadFile ¶ added in v0.4.1
MustReadFile read file contents, will panic on error
func MustRemove ¶ added in v0.4.1
func MustRemove(fpath string)
MustRemove removes the named file or (empty) directory. NOTICE: if error will panic
func OSTempDir ¶ added in v0.4.1
OSTempDir creates a new temp dir on os.TempDir and return the temp dir path Usage:
fsutil.OSTempDir("example.*.txt")
func OSTempFile ¶ added in v0.4.1
OSTempFile create an temp file on os.TempDir() Usage:
fsutil.OSTempFile("example.*.txt")
func PathExists ¶ added in v0.4.1
PathExists reports whether the named file or directory exists.
func QuickOpenFile ¶ added in v0.4.1
QuickOpenFile like os.OpenFile
func QuietRemove ¶ added in v0.4.1
func QuietRemove(fpath string)
QuietRemove removes the named file or (empty) directory. NOTICE: will ignore error
func ReadExistFile ¶ added in v0.4.1
ReadExistFile read file contents if exist, will panic on error
func ReadString ¶ added in v0.4.1
func ReaderMimeType ¶ added in v0.4.1
ReaderMimeType get the io.Reader mimeType Usage:
file, err := os.Open(filepath) if err != nil { return } mime := ReaderMimeType(file)
func TempDir ¶ added in v0.4.1
TempDir creates a new temp dir and return the temp dir path Usage:
fsutil.TempDir("", "example.*.txt")
func TempFile ¶ added in v0.4.1
TempFile is alias of ioutil.TempFile Usage:
fsutil.TempFile("", "example.*.txt")
func Unzip ¶
Unzip a zip archive from https://blog.csdn.net/wangshubo1989/article/details/71743374
Types ¶
type DirFilterFunc ¶ added in v0.4.1
DirFilterFunc for filter file path.
func DirNameFilterFunc ¶ added in v0.4.1
func DirNameFilterFunc(names []string, include bool) DirFilterFunc
DirNameFilterFunc filter filepath by given dir names.
func DotDirFilterFunc ¶ added in v0.4.1
func DotDirFilterFunc(include bool) DirFilterFunc
DotDirFilterFunc filter dot dirname. eg: ".idea"
func (DirFilterFunc) FilterDir ¶ added in v0.4.1
func (fn DirFilterFunc) FilterDir(dirPath, dirName string) bool
FilterDir Filter for filter file path.
type FileFilter ¶ added in v0.4.1
FileFilter for filter file path.
type FileFilterFunc ¶ added in v0.4.1
FileFilterFunc for filter file path.
func DotFileFilterFunc ¶ added in v0.4.1
func DotFileFilterFunc(include bool) FileFilterFunc
DotFileFilterFunc filter dot filename. eg: ".gitignore"
func ExtFilterFunc ¶ added in v0.4.1
func ExtFilterFunc(exts []string, include bool) FileFilterFunc
ExtFilterFunc filter filepath by given file ext.
Usage:
f := EmptyFiler() f.AddFilter(ExtFilterFunc([]string{".go", ".md"}, true)) f.AddFilter(ExtFilterFunc([]string{".log", ".tmp"}, false))
func GlobFilterFunc ¶ added in v0.4.1
func GlobFilterFunc(patterns []string, include bool) FileFilterFunc
GlobFilterFunc filter filepath by given patterns.
Usage:
f := EmptyFiler() f.AddFilter(GlobFilterFunc([]string{"*_test.go"}, true))
func ModTimeFilterFunc ¶ added in v0.4.1
func ModTimeFilterFunc(limitSec int, op rune, include bool) FileFilterFunc
ModTimeFilterFunc filter file by modify time.
func PathNameFilterFunc ¶ added in v0.4.1
func PathNameFilterFunc(names []string, include bool) FileFilterFunc
PathNameFilterFunc filter filepath by given path names.
func RegexFilterFunc ¶ added in v0.4.1
func RegexFilterFunc(pattern string, include bool) FileFilterFunc
RegexFilterFunc filter filepath by given regex pattern
Usage:
f := EmptyFiler() f.AddFilter(RegexFilterFunc(`[A-Z]\w+`, true))
func SuffixFilterFunc ¶ added in v0.4.1
func SuffixFilterFunc(suffixes []string, include bool) FileFilterFunc
SuffixFilterFunc filter filepath by given file ext.
Usage:
f := EmptyFiler() f.AddFilter(SuffixFilterFunc([]string{"util.go", ".md"}, true)) f.AddFilter(SuffixFilterFunc([]string{"_test.go", ".log"}, false))
func (FileFilterFunc) FilterFile ¶ added in v0.4.1
func (fn FileFilterFunc) FilterFile(filePath, filename string) bool
FilterFile Filter for filter file path.
type FileFinder ¶ added in v0.4.1
type FileFinder struct {
// contains filtered or unexported fields
}
FileFinder struct
func EmptyFinder ¶ added in v0.4.1
func EmptyFinder() *FileFinder
EmptyFinder new empty FileFinder instance
func NewFinder ¶ added in v0.4.1
func NewFinder(dirPaths []string, filePaths ...string) *FileFinder
NewFinder new instance with source dir paths.
func (*FileFinder) AddDir ¶ added in v0.4.1
func (f *FileFinder) AddDir(dirPaths ...string) *FileFinder
AddDir add source dir for find. alias of AddDirPath()
func (*FileFinder) AddDirFilter ¶ added in v0.4.1
func (f *FileFinder) AddDirFilter(filterFuncs ...DirFilter) *FileFinder
AddDirFilter for filter file contents
func (*FileFinder) AddDirPath ¶ added in v0.4.1
func (f *FileFinder) AddDirPath(dirPaths ...string) *FileFinder
AddDirPath add source dir for find
func (*FileFinder) AddFile ¶ added in v0.4.1
func (f *FileFinder) AddFile(filePaths ...string) *FileFinder
AddFile add source file. alias of AddFilePath()
func (*FileFinder) AddFileFilter ¶ added in v0.4.1
func (f *FileFinder) AddFileFilter(filterFuncs ...FileFilter) *FileFinder
AddFileFilter for filter filepath
func (*FileFinder) AddFilePath ¶ added in v0.4.1
func (f *FileFinder) AddFilePath(filePaths ...string) *FileFinder
AddFilePath add source file
func (*FileFinder) AddFilePaths ¶ added in v0.4.1
func (f *FileFinder) AddFilePaths(filePaths []string)
AddFilePaths set founded files
func (*FileFinder) AddFilter ¶ added in v0.4.1
func (f *FileFinder) AddFilter(filterFuncs ...interface{}) *FileFinder
AddFilter for filter filepath or dirpath
func (*FileFinder) Each ¶ added in v0.4.1
func (f *FileFinder) Each(fn func(filePath string))
Each each file paths.
func (*FileFinder) EachContents ¶ added in v0.4.1
func (f *FileFinder) EachContents(fn func(contents, filePath string))
EachContents each file contents
func (*FileFinder) EachFile ¶ added in v0.4.1
func (f *FileFinder) EachFile(fn func(file *os.File))
EachFile each file os.File
func (*FileFinder) EachStat ¶ added in v0.4.1
func (f *FileFinder) EachStat(fn func(fi os.FileInfo, filePath string))
EachStat each file os.FileInfo
func (*FileFinder) ExcludeDir ¶ added in v0.4.1
func (f *FileFinder) ExcludeDir(dirs ...string) *FileFinder
ExcludeDir exclude dir names.
func (*FileFinder) ExcludeDotDir ¶ added in v0.4.1
func (f *FileFinder) ExcludeDotDir(exclude ...bool) *FileFinder
ExcludeDotDir exclude dot dir names. eg: ".idea"
func (*FileFinder) ExcludeDotFile ¶ added in v0.4.1
func (f *FileFinder) ExcludeDotFile(exclude ...bool) *FileFinder
ExcludeDotFile exclude dot dir names. eg: ".gitignore"
func (*FileFinder) ExcludeName ¶ added in v0.4.1
func (f *FileFinder) ExcludeName(files ...string) *FileFinder
ExcludeName exclude file names.
func (*FileFinder) Find ¶ added in v0.4.1
func (f *FileFinder) Find() *FileFinder
Find find file paths.
func (*FileFinder) FindAll ¶ added in v0.4.1
func (f *FileFinder) FindAll() []string
FindAll find and return founded file paths.
func (*FileFinder) NoDotDir ¶ added in v0.4.1
func (f *FileFinder) NoDotDir(exclude ...bool) *FileFinder
NoDotDir exclude dot dir names. alias of ExcludeDotDir().
func (*FileFinder) NoDotFile ¶ added in v0.4.1
func (f *FileFinder) NoDotFile(exclude ...bool) *FileFinder
NoDotFile exclude dot dir names. alias of ExcludeDotFile().
func (*FileFinder) String ¶ added in v0.4.1
func (f *FileFinder) String() string
String all file paths
func (*FileFinder) WithDirFilter ¶ added in v0.4.1
func (f *FileFinder) WithDirFilter(filterFuncs ...DirFilter) *FileFinder
WithDirFilter for filter func for filtering file contents
func (*FileFinder) WithFileFilter ¶ added in v0.4.1
func (f *FileFinder) WithFileFilter(filterFuncs ...FileFilter) *FileFinder
WithFileFilter for filter func for filtering filepath
func (*FileFinder) WithFilter ¶ added in v0.4.1
func (f *FileFinder) WithFilter(filterFuncs ...interface{}) *FileFinder
WithFilter add filter func for filtering filepath or dirpath
type FileMeta ¶ added in v0.4.1
type FileMeta struct {
// contains filtered or unexported fields
}
FileMeta struct
type FilterFunc ¶ added in v0.4.1
FilterFunc for filter file path.
func (FilterFunc) Filter ¶ added in v0.4.1
func (fn FilterFunc) Filter(filePath, filename string) bool
Filter for filter file path.
type FindResults ¶ added in v0.4.1
type FindResults struct {
// contains filtered or unexported fields
}
FindResults struct
func (*FindResults) AddFilters ¶ added in v0.4.1
func (r *FindResults) AddFilters(filterFuncs ...FileFilter) *FindResults
AddFilters Result get find paths
func (*FindResults) Each ¶ added in v0.4.1
func (r *FindResults) Each() *FindResults
Each Result get find paths
func (*FindResults) Filter ¶ added in v0.4.1
func (r *FindResults) Filter() *FindResults
Filter Result get find paths
func (*FindResults) Result ¶ added in v0.4.1
func (r *FindResults) Result() []string
Result get find paths