gfile

通用的文件管理模块。

使用方式:

  1. import "gitee.com/johng/gf/g/os/gfile"

方法列表:godoc.org/github.com/johng-cn/gf/g/os/gfile

  1. func Basename(path string) string
  2. func Chmod(path string, mode os.FileMode) error
  3. func Copy(src string, dst string) error
  4. func Create(path string) error
  5. func Dir(path string) string
  6. func DirNames(path string) ([]string, error)
  7. func Exists(path string) bool
  8. func Ext(path string) string
  9. func FormatSize(raw float64) string
  10. func Glob(pattern string, onlyNames ...bool) ([]string, error)
  11. func GoRootOfBuild() string
  12. func Home() (string, error)
  13. func Info(path string) *os.FileInfo
  14. func IsDir(path string) bool
  15. func IsFile(path string) bool
  16. func IsReadable(path string) bool
  17. func IsWritable(path string) bool
  18. func MTime(path string) int64
  19. func MTimeMillisecond(path string) int64
  20. func MainPkgPath() string
  21. func Mkdir(path string) error
  22. func Move(src string, dst string) error
  23. func Open(path string) (*os.File, error)
  24. func OpenWithFlag(path string, flag int) (*os.File, error)
  25. func OpenWithFlagPerm(path string, flag int, perm int) (*os.File, error)
  26. func Pwd() string
  27. func ReadableSize(path string) string
  28. func RealPath(path string) string
  29. func Remove(path string) error
  30. func Rename(src string, dst string) error
  31. func ScanDir(path string, pattern string, recursive ...bool) ([]string, error)
  32. func SelfDir() string
  33. func SelfPath() string
  34. func Size(path string) int64
  35. func TempDir() string
  36. func Truncate(path string, size int) error
  37. func PutBinContents(path string, content []byte) error
  38. func PutBinContentsAppend(path string, content []byte) error
  39. func PutContents(path string, content string) error
  40. func PutContentsAppend(path string, content string) error
  41. func GetBinContents(path string) []byte
  42. func GetBinContentsByTwoOffsets(file *os.File, start int64, end int64) []byte
  43. func GetBinContentsByTwoOffsetsByPath(path string, start int64, end int64) []byte
  44. func GetBinContentsTilChar(file *os.File, char byte, start int64) ([]byte, int64)
  45. func GetBinContentsTilCharByPath(path string, char byte, start int64) ([]byte, int64)
  46. func GetContents(path string) string
  47. func GetNextCharOffset(file *os.File, char byte, start int64) int64
  48. func GetNextCharOffsetByPath(path string, char byte, start int64) int64

gfile模块是对文件操作的进一步封装,提供了常用的,简易的API来操作底层文件,隐藏了复杂的底层实现细节。