123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- package main
- import (
- "log"
- "strings"
- "github.com/studio-b12/gowebdav"
- )
- func Statistics() {
- log.Println("获取:", *date, " 期间上传的数据量")
- path := "云盘管理/日志/机电学院"
- getRemoteFilePath(webdav, user, secert, path, path)
- path = "云盘管理/日志/中电科"
- getRemoteFilePath(webdav, user, secert, path, path)
- path = "云盘管理/日志/华软"
- getRemoteFilePath(webdav, user, secert, path, path)
- }
- // 获取数据目录
- func getRemoteFilePath(webdav, user, secert, remote, company string) {
- success := 0
- //failed := 0
- client := gowebdav.NewAuthClient(webdav, gowebdav.NewAutoAuth(user, secert))
- client.Connect()
- // 获取根目录列表
- entries, err := client.ReadDir(remote)
- if err != nil {
- log.Fatal(err)
- }
- // 遍历目录结构
- for _, entry := range entries {
- // log.Println(remote + "/" + entry.Name())
- if entry.IsDir() {
- // 如果是目录,则递归遍历子目录
- success = readDirRecursive(client, remote+"/"+entry.Name(), success)
- } else {
- pth := rename(client, remote+"/"+entry.Name())
- log.Println(pth)
- info, _ := client.Read(pth)
- str := string(info)
- // log.Println(str)
- success += strings.Count(str, "文件上传成功!")
- }
- }
- log.Println(company, "上传成功数量为:", success)
- }
- // 递归遍历目录结构
- func readDirRecursive(client *gowebdav.Client, path string, success int) int {
- entries, err := client.ReadDir(path)
- if err != nil {
- log.Fatal(err)
- }
- for _, entry := range entries {
- if entry.IsDir() {
- // 如果是目录,则递归遍历子目录
- success = readDirRecursive(client, path+"/"+entry.Name(), success)
- } else {
- file_path := path + "/" + entry.Name()
- if !strings.Contains(file_path, *date) {
- continue
- }
- //计算成功
- pth := rename(client, file_path)
- info, _ := client.Read(pth)
- str := string(info)
- // log.Println(str)
- success += strings.Count(str, "文件上传成功!")
- }
- }
- return success
- }
- func rename(client *gowebdav.Client, path string) string {
- newpath := path
- if strings.Contains(path, ".log") {
- newpath = strings.ReplaceAll(path, ".log", ".txt")
- client.Rename(path, newpath, true)
- }
- return newpath
- }
|