zdpgo_file

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2022 License: MIT Imports: 18 Imported by: 1

README

zdpgo_file

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

一、概述

1.1 项目地址
1.1 功能
  • 判断文件是否存在
  • 获取文件大小
  • 获取文件夹大小

二、快速入门

2.1 判断文件是否存在
func TestFileExists(t *testing.T) {
	fmt.Println(FileExists("./file.go"))
	fmt.Println(FileExists("./file111.go"))
}
2.2 获取文件大小
func TestFileSize(t *testing.T){
	fmt.Println(FileSize("./file.go"))
	fmt.Println(FileSize("./file1.go"))
}
2.3 获取文件夹大小
func TestDirectorySize(t *testing.T){
	fmt.Println(DirectorySize("D:\\BaiduNetdiskWorkspace\\文档"))
}

三、保存文件

3.1 二维字符串切片保存为csv文件
package main

import "github.com/zhangdapeng520/zdpgo_file"

func main() {
	das := zdpgo_file.DoubleArrayString{
		Data: [][]string{
			{"a","b","c"},
			{"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"},
		},
	}
	das.SaveCsv("test.csv")
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DirectorySize

func DirectorySize(path string) (int64, error)

文件夹占用磁盘大小

func FileExists

func FileExists(path string) bool

FileExists 判断文件是否存在

func FileSize

func FileSize(path string) int64

FileSize 获取文件大小

func SaveCsv

func SaveCsv(filePath string, data [][]string) bool

将数据保存为csv文件

func SaveCsvAsync

func SaveCsvAsync(filePath string, data [][]string, ch chan bool)

将数据保存为csv文件

Types

type DoubleArrayString

type DoubleArrayString struct {
	Data [][]string
}

二维字符串切片结构体

func (*DoubleArrayString) SaveCsv

func (das *DoubleArrayString) SaveCsv(filepath string)

实现保存为CSV的方法

type File

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

File 文件对象

func NewFile

func NewFile(config FileConfig) *File

NewFile 新建文件对象 @param config 配置对象

func (File) CreateServer

func (f File) CreateServer(host string, port uint16)

CreateServer 创建文件服务器 @param host 文件服务器主机地址,可以收0.0.0.0 @param port 文件服务器端口号

func (*File) DownloadNetImage

func (f *File) DownloadNetImage(saveDir string, imageUrl string) error

DownloadNetImage 下载网络图片

func (*File) DownloadNetImageMany

func (f *File) DownloadNetImageMany(saveDir string, imageUrls []string)

DownloadNetImageMany 批量下载图片

func (*File) ExcelAddChart

func (f *File) ExcelAddChart(sheetName string, cellName string, jsonData string) (err error)

ExcelAddChart 添加图表到Excel

func (*File) ExcelAddPicture

func (f *File) ExcelAddPicture(sheetName string, cellName string, img string, jsonConfig string) (err error)

func (*File) ExcelClose

func (f *File) ExcelClose() (err error)

func (*File) ExcelNew

func (f *File) ExcelNew(config FileExcelConfig)

ExcelNew 创建Excel文件

func (*File) ExcelNewSheet

func (f *File) ExcelNewSheet(name string) int

ExcelNewSheet 创建工作簿

func (*File) ExcelSave

func (f *File) ExcelSave() error

ExcelSave 保存Excel

func (*File) ExcelSetActiveSheet

func (f *File) ExcelSetActiveSheet(sheetIndex int)

ExcelSetActiveSheet 激活单元格

func (*File) ExcelSetCellValue

func (f *File) ExcelSetCellValue(sheet string, cell string, value interface{}) error

ExcelSetCellValue 设置单元格的值

func (File) Exit

func (f File) Exit()

Exit 退出程序

func (*File) GetCellValue

func (f *File) GetCellValue(sheetName string, cellName string) (value string, err error)

GetCellValue 读取单元格数据

func (*File) GetSheetData

func (f *File) GetSheetData(sheetName string) (data [][]string, err error)

GetSheetData 读取整张工作簿

func (File) RecvFile

func (f File) RecvFile(conn net.Conn, fileName string)

获取文件内容,并写入到文件中

func (File) SendFile

func (f File) SendFile(host string, port uint16, path string, name string)

SendFile 向文件服务器发送文件 @param host 文件服务器主机地址 @param port 文件服务器端口号

type FileConfig

type FileConfig struct {
	Debug       bool   // 是否为debug模式
	LogFilePath string // 日志存放路径
}

FileConfig 文件配置

type FileExcelConfig

type FileExcelConfig struct {
	FileName string // 文件名
}

FileExcelConfig excel文件配置

type ICsv

type ICsv interface {
	// 保存csv的方法
	SaveCsv(fileName string)
}

保存CSV文件

Directories

Path Synopsis
examples
z01_save_csv command

Jump to

Keyboard shortcuts

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