zdpgo_file

package module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: May 2, 2022 License: MIT Imports: 10 Imported by: 1

README

zdpgo_file

Golang操作文件或者文件夹的快捷组件

项目地址:https://github.com/zhangdapeng520/zdpgo_file

版本历史

  • v0.1.0 2022/2/7
  • v0.1.1 2022/4/3
  • v0.1.2 2022/4/21
  • v0.1.3 2022/5/2 新增:替换指定目录下的文件名

使用示例

读写csv
package main

import (
	"fmt"
	"github.com/zhangdapeng520/zdpgo_file"
)

func main() {
	f := zdpgo_file.New()
	data := [][]string{
		{"a[test]", "b", "c[test]"},
		{"111", "222", "333"},
		{"111", "222", "333"},
		{"111", "222", "333"},
		{"111", "222", "333"},
		{"111", "222", "333"},
		{"111", "222", "333"},
		{"111", "222", "333"},
		{"111", "222", "333"},
		{"111", "222", "333"},
		{"111", "222", "333"},
	}

	// 写入
	f.Csv.Write("test.csv", data)

	// 读取
	dataNew, err := f.Csv.Read("test.csv")
	if err != nil {
		fmt.Println(err)
	}
	fmt.Println(dataNew)
}
文件夹操作
package main

import (
	"fmt"
	"github.com/zhangdapeng520/zdpgo_file"
)

func main() {
	f := zdpgo_file.New()
	fmt.Println(f.Directory.GetDirectorySize("../download"))
	fmt.Println(f.Directory.IsExist("D:\\BaiduNetdiskWorkspace\\文档"))
	fmt.Println(f.Directory.CreateMultiDir("logs/zdpgo"))
}
下载网络文件
package main

import (
	"fmt"
	"github.com/zhangdapeng520/zdpgo_file"
)

func main() {
	f := zdpgo_file.New()
	savePath := "./"

	// 单个下载
	url := "https://avatar.csdnimg.cn/2/9/0/1_togolife.jpg"
	err := f.Download.Download(savePath, url)
	if err != nil {
		fmt.Println("下载失败:", err)
	} else {
		fmt.Println("下载成功")
	}

	// 批量下载
	urls := []string{
		"https://alifei04.cfp.cn/creative/vcg/nowarter800/new/VCG41N695593548.jpg",
		"https://tenfei02.cfp.cn/creative/vcg/nowarter800/new/VCG41N1014325904.jpg",
		"https://tenfei05.cfp.cn/creative/vcg/nowater800/new/VCG41545444880.jpg",
	}
	f.Download.Downloads(savePath, urls)
}
文件操作
package main

import (
	"fmt"
	"github.com/zhangdapeng520/zdpgo_file"
)

func main() {
	f := zdpgo_file.New()
	fmt.Println(f.File.Exists("./file.go"))
	fmt.Println(f.File.Exists("./file111.go"))

	fmt.Println(f.File.Size("./file.go"))
	fmt.Println(f.File.Size("./file1.go"))
}
去掉文件后缀
package main

import (
	"github.com/zhangdapeng520/zdpgo_file"
)

func main() {
	f := zdpgo_file.New()
	err := f.File.RemoveDirFilesSuffix("test")
	if err != nil {
		panic(err)
	}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type File

type File struct {
	// contains filtered or unexported fields
}

File 文件对象

func New added in v0.1.2

func New() *File

New 新建文件对象

func (*File) CreateMultiDir added in v0.1.3

func (f *File) CreateMultiDir(filePath string) error

CreateMultiDir 调用os.MkdirAll递归创建文件夹

func (*File) Exists added in v0.1.3

func (f *File) Exists(path string) bool

Exists 判断文件是否存在

func (*File) GetDirectorySize added in v0.1.3

func (f *File) GetDirectorySize(path string) (int64, error)

GetDirectorySize 文件夹占用磁盘大小

func (*File) IsExist added in v0.1.3

func (f *File) IsExist(path string) bool

IsExist 判断所给路径文件/文件夹是否存在(返回true是存在)

func (*File) MakeDirs added in v0.1.3

func (f *File) MakeDirs(filePath string) error

MakeDirs 创建多级目录

func (*File) ReadCsv added in v0.1.3

func (f *File) ReadCsv(fileName string) (data [][]string, err error)

Read 读取csv

func (*File) RemoveDirFilesSuffix added in v0.1.3

func (f *File) RemoveDirFilesSuffix(dirPath string) error

RemoveDirFilesSuffix 去掉指定目录下所有文件的后缀

func (*File) Rename added in v0.1.3

func (f *File) Rename()

func (*File) ReplaceDirFilesName added in v0.1.3

func (f *File) ReplaceDirFilesName(dirPath string, oldStr, newStr string) error

ReplaceDirFilesName 替换指定目录下的文件名

func (*File) Size added in v0.1.3

func (f *File) Size(path string) int64

Size 获取文件大小

func (*File) WriteCsv added in v0.1.3

func (f *File) WriteCsv(filePath string, data [][]string) (err error)

Write 将数据保存为csv文件

Directories

Path Synopsis
examples
z01_csv command
z02_cirectory command
z03_download command
z04_file command

Jump to

Keyboard shortcuts

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