Documentation ¶
Index ¶
- Variables
- func Abs(path string) string
- func Basename(path string) string
- func Chdir(dir string) error
- func Chmod(path string, mode os.FileMode) error
- func Copy(src string, dst string) error
- func CopyDir(src string, dst string) (err error)
- func CopyFile(src, dst string) (err error)
- func Create(path string) (*os.File, error)
- func Dir(path string) string
- func DirNames(path string) ([]string, error)
- func Exists(path string) bool
- func Ext(path string) string
- func ExtName(path string) string
- func FormatSize(raw int64) string
- func GetBytes(path string) []byte
- func GetBytesByTwoOffsets(reader io.ReaderAt, start int64, end int64) []byte
- func GetBytesByTwoOffsetsByPath(path string, start int64, end int64) []byte
- func GetBytesTilChar(reader io.ReaderAt, char byte, start int64) ([]byte, int64)
- func GetBytesTilCharByPath(path string, char byte, start int64) ([]byte, int64)
- func GetBytesWithCache(path string, duration ...time.Duration) []byte
- func GetContents(path string) string
- func GetContentsWithCache(path string, duration ...time.Duration) string
- func GetNextCharOffset(reader io.ReaderAt, char byte, start int64) int64
- func GetNextCharOffsetByPath(path string, char byte, start int64) int64
- func Glob(pattern string, onlyNames ...bool) ([]string, error)
- func Home(names ...string) (string, error)
- func Info(path string) (os.FileInfo, error)
- func IsDir(path string) bool
- func IsEmpty(path string) bool
- func IsFile(path string) bool
- func IsReadable(path string) bool
- func IsWritable(path string) bool
- func Join(paths ...string) string
- func MTime(path string) time.Time
- func MTimestamp(path string) int64
- func MTimestampMilli(path string) int64
- func MainPkgPath() string
- func Mkdir(path string) error
- func Move(src string, dst string) error
- func Name(path string) string
- func Open(path string) (*os.File, error)
- func OpenFile(path string, flag int, perm os.FileMode) (*os.File, error)
- func OpenWithFlag(path string, flag int) (*os.File, error)
- func OpenWithFlagPerm(path string, flag int, perm os.FileMode) (*os.File, error)
- func PutBytes(path string, content []byte) error
- func PutBytesAppend(path string, content []byte) error
- func PutContents(path string, content string) error
- func PutContentsAppend(path string, content string) error
- func Pwd() string
- func ReadByteLines(file string, callback func(bytes []byte) error) error
- func ReadLines(file string, callback func(text string) error) error
- func ReadLinesBytes(file string, callback func(bytes []byte) error) error
- func ReadableSize(path string) string
- func RealPath(path string) string
- func Remove(path string) error
- func Rename(src string, dst string) error
- func ReplaceDir(search, replace, path, pattern string, recursive ...bool) error
- func ReplaceDirFunc(f func(path, content string) string, path, pattern string, recursive ...bool) error
- func ReplaceFile(search, replace, path string) error
- func ReplaceFileFunc(f func(path, content string) string, path string) error
- func ScanDir(path string, pattern string, recursive ...bool) ([]string, error)
- func ScanDirFile(path string, pattern string, recursive ...bool) ([]string, error)
- func ScanDirFileFunc(path string, pattern string, recursive bool, handler func(path string) string) ([]string, error)
- func ScanDirFunc(path string, pattern string, recursive bool, handler func(path string) string) ([]string, error)
- func Search(name string, prioritySearchPaths ...string) (realPath string, err error)
- func SelfDir() string
- func SelfName() string
- func SelfPath() string
- func Size(path string) int64
- func SortFiles(files []string) []string
- func Stat(path string) (os.FileInfo, error)
- func StrToSize(sizeStr string) int64
- func TempDir(names ...string) string
- func Truncate(path string, size int) error
Constants ¶
This section is empty.
Variables ¶
var ( // Separator 操作系统文件路径分隔符 Separator = string(filepath.Separator) // DefaultPermOpen 是默认打开文件的权限值 DefaultPermOpen = os.FileMode(0666) // DefaultPermCopy 是默认copy文件或文件夹的权限值 DefaultPermCopy = os.FileMode(0777) )
var (
// DefaultReadBuffer 读取文件的缓冲区大小
DefaultReadBuffer = 1024
)
Functions ¶
func Basename ¶
Basename returns the last element of path, which contains file extension. Trailing path separators are removed before extracting the last element. If the path is empty, Base returns ".". If the path consists entirely of separators, Basename returns a single separator. Example: /var/www/file.js -> file.js file.js -> file.js
func Dir ¶
Dir 返回Path的最后一个元素以外的所有元素,通常是路径的目录。 删除最后一个元素后,Dir调用路径和尾部的Clean。 删除斜杠。 如果`path`为空,则Dir返回“.” 如果`path`为“.”,则Dir将该路径视为当前工作目录。 如果`path`全部由分隔符组成,则Dir返回单个分隔符。 除非是根目录,否则返回的路径不会以分隔符结尾。
func GetBytesByTwoOffsets ¶ added in v0.0.8
GetBytesByTwoOffsets 获取指定区间的字符内容
func GetBytesByTwoOffsetsByPath ¶ added in v0.0.8
GetBytesByTwoOffsetsByPath 获取文件中从start开始到end结束区间的内容
func GetBytesTilChar ¶ added in v0.0.8
GetBytesTilChar 获取从指定字符到结尾所有的字符数组
func GetBytesTilCharByPath ¶ added in v0.0.8
GetBytesTilCharByPath 获取文件中从start位置开始,找到的第一个char字符,一直到文件结尾的内容
func GetBytesWithCache ¶ added in v0.0.8
GetBytesWithCache 获取文件信息,并且缓存
func GetContentsWithCache ¶ added in v0.0.8
GetContentsWithCache 从缓存中获取文件信息,返回字符串
func GetNextCharOffset ¶ added in v0.0.8
GetNextCharOffset 从指定位置开始读取数据,碰到与char相等的字节返回它所在的位置
func GetNextCharOffsetByPath ¶ added in v0.0.8
GetNextCharOffsetByPath 获取指定文件中char所在的位置,从start开始查找
func Glob ¶
Glob returns the names of all files matching pattern or nil if there is no matching file. The syntax of patterns is the same as in Match. The pattern may describe hierarchical names such as /usr/*/bin/ed (assuming the Separator is '/').
Glob ignores file system errors such as I/O errors reading directories. The only possible returned error is ErrBadPattern, when pattern is malformed.
func MTimestampMilli ¶ added in v0.0.3
MTimestampMilli 返回文件或目录路径的最后修改毫秒时间戳
func MainPkgPath ¶ added in v0.0.8
func MainPkgPath() string
MainPkgPath 返回main包的绝对文件路径, 其中主要包含入口功能。 它只在开发环境中可用。 注1:仅对源代码开发环境有效, 只对生成此可执行文件的系统有效。 注意2:当该方法第一次被调用时,如果它是在一个异步的goroutine中,该方法可能不会获得主包路径。
func Name ¶
Name returns the last element of path without file extension. Example: /var/www/file.js -> file file.js -> file
func OpenFile ¶
OpenFile 打开文件/文件夹,可以使用自定义flag和mode。 <flag> : O_RDONLY, O_RDWR, O_RDWR|O_CREATE|O_TRUNC,
func OpenWithFlag ¶ added in v0.0.8
OpenWithFlag 打开文件/文件夹,可以使用自定义flag。
func OpenWithFlagPerm ¶
OpenWithFlagPerm 打开文件/文件夹,可以使用自定义flag和mode。 The parameter <flag> is like: O_RDONLY, O_RDWR, O_RDWR|O_CREATE|O_TRUNC, etc. The parameter <perm> is like: 0600, 0666, 0777, etc.
func PutBytesAppend ¶ added in v0.0.8
PutBytesAppend 追加写入字节数组内容到文件末尾,文件不存在则创建,已存在则写到末尾
func PutContents ¶ added in v0.0.8
PutContents 写入字符串内容到文件,文件不存在则创建,如果存在则从头开始写
func PutContentsAppend ¶ added in v0.0.8
PutContentsAppend 追加写入字符串内容到文件末尾,文件不存在则创建,已存在则写到末尾
func ReadByteLines ¶ added in v0.0.8
ReadByteLines 逐行读取文件内容,读取一行回调一次callback方法
func ReadLinesBytes ¶ added in v0.0.8
ReadLinesBytes 逐行读取文件内容,读取一行回调一次callback方法
func Remove ¶
Remove deletes all file/directory with <path> parameter. If parameter <path> is directory, it deletes it recursively.
func ReplaceDir ¶ added in v0.0.8
ReplaceDir 替换文件夹下的文件中的指定内容
func ReplaceDirFunc ¶ added in v0.0.8
func ReplaceDirFunc(f func(path, content string) string, path, pattern string, recursive ...bool) error
ReplaceDirFunc 使用回调函数替换文件夹下文件中的内容
func ReplaceFile ¶ added in v0.0.8
ReplaceFile 替换文件中的指定内容 从文件中查找内容,并替换,然后写入文件
func ReplaceFileFunc ¶ added in v0.0.8
ReplaceFileFunc 通过func处理得到要替换的文件内容,替换path中的内容
func ScanDirFile ¶ added in v0.0.3
ScanDirFile 遍历返回文件夹中的文件
func ScanDirFileFunc ¶ added in v0.0.8
func ScanDirFileFunc(path string, pattern string, recursive bool, handler func(path string) string) ([]string, error)
ScanDirFileFunc 遍历文件夹中的文件,并执行回调函数
func ScanDirFunc ¶ added in v0.0.8
func ScanDirFunc(path string, pattern string, recursive bool, handler func(path string) string) ([]string, error)
ScanDirFunc 扫描文件夹,找到匹配的文件夹,并且执行回调函数
func Search ¶ added in v0.0.8
Search 在以下路径中按名字有限搜索文件 prioritySearchPaths, Pwd()、SelfDir()、MainPkgPath(). 如果找到,则返回绝对路径,如果未找到则返回空字符串,并报错
Types ¶
This section is empty.