123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- 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)
- // 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)
- }
- m := map[string]bool{}
- // 遍历目录结构
- for _, entry := range entries {
- // log.Println(remote + "/" + entry.Name())
- if entry.IsDir() {
- // 如果是目录,则递归遍历子目录
- success, failed = readDirRecursive(client, remote+"/"+entry.Name(), success, m, failed)
- } else {
- pth := rename(client, remote+"/"+entry.Name())
- if m[pth] {
- continue
- }
- m[pth] = true
- log.Println(pth)
- info, _ := client.Read(pth)
- str := string(info)
- // log.Println(str)
- success += strings.Count(str, "文件上传成功!")
- failed += strings.Count(str, "已经上传过,过滤")
- }
- }
- log.Println(company, "上传成功数量为:", success, "失败数量为:", failed)
- }
- // 递归遍历目录结构
- func readDirRecursive(client *gowebdav.Client, path string, success int, m map[string]bool, failed int) (int, int) {
- entries, err := client.ReadDir(path)
- if err != nil {
- log.Fatal(err)
- }
- for _, entry := range entries {
- if entry.IsDir() {
- // 如果是目录,则递归遍历子目录
- success, failed = readDirRecursive(client, path+"/"+entry.Name(), success, m, failed)
- } else {
- file_path := path + "/" + entry.Name()
- if !strings.Contains(file_path, *date) {
- continue
- } else {
- log.Println(file_path)
- }
- //计算成功
- pth := rename(client, file_path)
- if m[pth] {
- continue
- }
- m[pth] = true
- info, _ := client.Read(pth)
- str := string(info)
- // log.Println("ssss:", str)
- success += strings.Count(str, "文件上传成功!")
- // log.Println(file_path, strings.Count(str, "文件上传成功!"))
- failed += strings.Count(str, "已经上传过,过滤")
- }
- }
- return success, failed
- }
- 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
- }
|