gfs

package
v1.0.8 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2022 License: Apache-2.0 Imports: 6 Imported by: 7

README

文件操作工具

工具加载

import (
	"github.com/cnlesscode/gotool/gfs"
)

PathExists(文件或文件夹路径 string) bool

函数功能 : 判断文件或者文件夹是否存在 返回格式 : bool

fmt.Printf("%v\n", gfs.PathExists("./a.txt")) // true || false

FileExists(文件路径 string) bool

函数功能 : 判断文件是否存在 返回格式 : bool

fmt.Printf("%v\n", gfs.FileExists("./a.txt")) // true || false

DirExists(文件夹路径 string) bool

函数功能 : 判断文件夹是否存在 返回格式 : bool

fmt.Printf("%v\n", gfs.DirExists("./fs")) // true || false

CopyFile(源文件路径,目标文件路径) error

函数功能 : 拷贝文件 返回格式 : error

err := gfs.CopyFile("./a.txt", "./b.txt") // true
if err != nil {
	fmt.Printf("error: %v\n", err.Error())
}

CopyDir(源文件夹路径,目标文件夹路径) error

函数功能 : 拷贝文件夹 返回格式 : error

err := gfs.CopyDir("./fs", "./a") // true
if err != nil {
	fmt.Printf("error: %v\n", err.Error())
}

MakeDir(文件夹路径 string) error

函数功能 : 创建文件夹 返回格式 : error

err := gfs.MakeDir("./a/b/c") // true
if err != nil {
	fmt.Printf("error: %v\n", err.Error())
}

RemoveDir(文件夹路径 string) error

函数功能 : 删除文件夹 返回格式 : error

err := gfs.RemoveDir("./a") // true
if err != nil {
	fmt.Printf("error: %v\n", err.Error())
}

DirSize(文件夹路径 string) (size, error)

函数功能 : 获取文件夹大小, 单位字节 返回格式 : 文件夹大小, error

size, err := gfs.DirSize("./fs") // true
if err != nil {
	fmt.Printf("error: %v\n", err.Error())
} else {
	fmt.Printf("size: %v\n", size)
}

ModifyTime(文件/夹路径 string) (int64, error)

函数功能 : 获取文件夹或文件夹修改时间 返回格式 : 文件夹或文件夹修改时间, error

modTime, err := gfs.ModifyTime("./fs")
if err != nil {
	fmt.Printf("err.Error(): %v\n", err.Error())
} else {
	fmt.Printf("modTime: %v\n", modTime)
}

ReadFile(文件路径 string) (string, error)

函数功能 : 读取文件内容 返回格式 : 文件内容, error

content, err := gfs.ReadFile("./a.txt")
	if err != nil {
		fmt.Printf("err.Error(): %v\n", err.Error())
	} else {
		fmt.Printf("content: %v\n", content)
	}
}

WriteContentToFile(内容 string, 文件夹路径[*必须以/结尾] string, 文件名称 string) error

函数功能 : 向文件内写入数据 [ 自动创建文件 ] 返回格式 : error

err := gfs.WriteContentToFile("content ...", "./a/b/c/", "ab.txt")
if err != nil {
	fmt.Printf("err.Error(): %v\n", err.Error())
}

AppendContentToFile(内容 string, 文件路径 string) error

函数功能 : 向文件尾部追加内容 返回格式 : error

err := gfs.AppendContentToFile("\nappend content ...", "./ab.txt")
	if err != nil {
		fmt.Printf("err.Error(): %v\n", err.Error())
	}
}

PrependContentToFile(内容 string, 文件路径 string) error

函数功能 : 向文件头部部追加内容 返回格式 : error

err := gfs.PrependContentToFile("Prepend content ...\n", "./ab.txt")
if err != nil {
	fmt.Printf("err.Error(): %v\n", err.Error())
}

GetExtension(文件路径 string) string

函数功能 : 获取文件扩展名 返回格式 : string

fmt.Printf("%v\n", gfs.GetExtension("./a/b/c.tXt"))

GetFileName(文件路径 string, 分隔符) string

函数功能 : 从路径中获取文件名 返回格式 : string

fileName := gfs.GetFileName("../a/b/c/rd.md", "/")
fmt.Printf("fileName: %v\n", fileName)
// fileName: rd.md

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendContentToFile

func AppendContentToFile(content string, fileUrl string) error

Append Content To File

func CopyDir

func CopyDir(src string, dst string) error

Copy Dir

func CopyFile

func CopyFile(srcUri string, dstUri string) error

Copy File

func DirExists

func DirExists(dir string) bool

Dir Exists

func DirSize

func DirSize(path string) (int64, error)

Dir Size

func FileExists

func FileExists(fileUri string) bool

File Exists

func GetExtension

func GetExtension(fileName string) string

Get Extension

func GetFileName

func GetFileName(filePath, Splitor string) string

GET File Name

func MakeDir

func MakeDir(dir string) error

Make Dir

func ModifyTime

func ModifyTime(path string) (int64, error)

ModifyTime

func PathExists

func PathExists(path string) bool

Path Exists

func PrependContentToFile

func PrependContentToFile(content string, fileUrl string) error

Prepend Content To File

func ReadFile

func ReadFile(fileUrl string) (string, error)

Read file

func RemoveDir

func RemoveDir(dir string) error

Remove Dir

func WriteContentToFile

func WriteContentToFile(content string, dir string, fileUrl string) error

Write Content To File

Types

This section is empty.

Jump to

Keyboard shortcuts

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