File

package
v0.0.0-...-3e87f45 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2022 License: MPL-2.0 Imports: 12 Imported by: 0

Documentation

Overview

* @Author: NyanCatda * @Date: 2022-03-08 21:26:55 * @LastEditTime: 2022-03-22 23:21:11 * @LastEditors: NyanCatda * @Description: 路径检查 * @FilePath: \Momizi\Tools\File\Dir.go

* @Author: NyanCatda * @Date: 2022-03-22 22:10:18 * @LastEditTime: 2022-03-22 23:21:06 * @LastEditors: NyanCatda * @Description: 文件操作 * @FilePath: \Momizi\Tools\File\File.go

* @Author: NyanCatda * @Date: 2022-03-28 13:24:47 * @LastEditTime: 2022-03-28 13:52:20 * @LastEditors: NyanCatda * @Description: 文件类型判断 * @FilePath: \Momizi\Tools\File\FileType.go

* @Author: NyanCatda * @Date: 2022-03-23 13:59:28 * @LastEditTime: 2022-04-02 02:57:34 * @LastEditors: McPlus * @Description: 文件读写操作 * @FilePath: \Momizi\Tools\File\ReadWrite.go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Copy

func Copy(Path string, NewPath string) (int64, error)

*

  • @description: 复制文件
  • @param {string} Path 源文件路径
  • @param {string} NewPath 目标文件路径
  • @return {int64} 文件大小(Byte)
  • @return {error} 错误信息

func CorrectFileType

func CorrectFileType(Path string) (string, error)

*

  • @description: 纠正文件类型
  • @param {string} Path 文件路径
  • @return {string} 纠正后的文件路径
  • @return {error} 错误信息

func Delete

func Delete(Path string) (bool, error)

*

  • @description: 删除文件/文件夹
  • @param {string} Path 文件/文件夹路径
  • @return {bool} 是否删除成功
  • @return {error} 错误信息

func Exists

func Exists(Path string) bool

*

  • @description: 判断所给路径文件/文件夹是否存在
  • @param {string} Path 文件/文件夹路径
  • @return {bool} 是否存在

func GetFileSize

func GetFileSize(FilePath string) (int64, error)

*

  • @description: 获取文件大小
  • @param {string} FilePath 文件路径
  • @return {int64} 文件大小(Byte)
  • @return {error} 错误信息

func GetFileType

func GetFileType(FileBody []byte) string

*

  • @description: 获取文件类型
  • @param {[]byte} FileBody 文件字节流
  • @return {string} 文件类型(扩展名)

func GetFilesList

func GetFilesList(DirPth string) ([]string, error)

*

  • @description: 遍历目录下的所有文件(包含子目录)
  • @param {string} DirPth
  • @return {[]string} 文件路径列表
  • @return {error} 错误信息

func IsDir

func IsDir(Path string) bool

*

  • @description: 判断所给路径是否为文件夹
  • @param {string} Path 文件夹路径
  • @return {bool} 是否为文件夹

func IsFile

func IsFile(Path string) bool

*

  • @description: 判断所给路径是否为文件
  • @param {string} Path
  • @return {bool} 是否为文件

func MKDir

func MKDir(Path string) (bool, error)

*

  • @description: 创建文件夹,如果不存在则创建
  • @param {string} path 文件夹路径
  • @return {*}

func Move

func Move(Path string, NewPath string) error

*

  • @description: 移动文件
  • @param {string} Path 源文件路径
  • @param {string} NewPath 目标文件路径
  • @return {*}

Types

type ReadWrite

type ReadWrite struct {
	Path string
	File *os.File
}

func NewFileReadWrite

func NewFileReadWrite(Path string, Flag int) (*ReadWrite, error)

*

  • @description: 新建文件读写类
  • @param {string} Path 文件路径
  • @return {string} 文件内容

func (*ReadWrite) Close

func (ReadWrite *ReadWrite) Close() error

*

  • @description: 关闭文件
  • @param {*}
  • @return {error} 错误

func (*ReadWrite) Read

func (ReadWrite *ReadWrite) Read() (string, error)

*

  • @description: 读取文件(需要权限os.O_RDONLY)
  • @return {string} 文件内容
  • @return {error} 错误

func (*ReadWrite) WriteAppend

func (ReadWrite *ReadWrite) WriteAppend(Content string) error

*

  • @description: 追加写入文件(需要权限os.O_WRONLY|os.O_APPEND|os.O_CREATE)
  • @param {string} Content 文件内容
  • @return {error} 错误

func (*ReadWrite) WriteTo

func (ReadWrite *ReadWrite) WriteTo(Content string) error

*

  • @description: 覆盖写入文件(需要权限os.O_WRONLY|os.O_TRUNC|os.O_CREATE)
  • @param {string} Content 文件内容
  • @return {error} 错误

Jump to

Keyboard shortcuts

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