This repository has been archived by the owner on Jul 22, 2020. It is now read-only.
forked from Angey40/BaiduPCS-Go
/
ls.go
81 lines (67 loc) · 2.55 KB
/
ls.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package pcscommand
import (
"fmt"
"github.com/iikira/BaiduPCS-Go/baidupcs"
"github.com/iikira/BaiduPCS-Go/pcstable"
"github.com/iikira/BaiduPCS-Go/pcsutil/converter"
"github.com/iikira/BaiduPCS-Go/pcsutil/pcstime"
"github.com/olekukonko/tablewriter"
"os"
"strconv"
)
// LsOptions 列目录可选项
type LsOptions struct {
Total bool
}
// RunLs 执行列目录
func RunLs(path string, lsOptions *LsOptions, orderOptions *baidupcs.OrderOptions) {
path, err := getAbsPath(path)
if err != nil {
fmt.Println(err)
return
}
files, err := GetBaiduPCS().FilesDirectoriesList(path, orderOptions)
if err != nil {
fmt.Println(err)
return
}
fmt.Printf("\n当前目录: %s\n----\n", path)
tb := pcstable.NewTable(os.Stdout)
if lsOptions == nil {
lsOptions = &LsOptions{}
}
var (
fN, dN int64
)
if lsOptions.Total {
tb.SetHeader([]string{"#", "fs_id", "文件大小", "创建日期", "修改日期", "md5(截图请打码)", "文件(目录)"})
tb.SetColumnAlignment([]int{tablewriter.ALIGN_DEFAULT, tablewriter.ALIGN_RIGHT, tablewriter.ALIGN_RIGHT, tablewriter.ALIGN_LEFT, tablewriter.ALIGN_LEFT, tablewriter.ALIGN_LEFT, tablewriter.ALIGN_LEFT})
for k, file := range files {
if file.Isdir {
tb.Append([]string{strconv.Itoa(k), strconv.FormatInt(file.FsID, 10), "-", pcstime.FormatTime(file.Ctime), pcstime.FormatTime(file.Mtime), file.MD5, file.Filename + "/"})
continue
}
tb.Append([]string{strconv.Itoa(k), strconv.FormatInt(file.FsID, 10), converter.ConvertFileSize(file.Size), pcstime.FormatTime(file.Ctime), pcstime.FormatTime(file.Mtime), file.MD5, file.Filename})
}
fN, dN := files.Count()
tb.Append([]string{"", "", "总: " + converter.ConvertFileSize(files.TotalSize()), "", "", "", fmt.Sprintf("文件总数: %d, 目录总数: %d", fN, dN)})
} else {
tb.SetHeader([]string{"#", "文件大小", "修改日期", "文件(目录)"})
tb.SetColumnAlignment([]int{tablewriter.ALIGN_DEFAULT, tablewriter.ALIGN_RIGHT, tablewriter.ALIGN_LEFT, tablewriter.ALIGN_LEFT})
for k, file := range files {
if file.Isdir {
tb.Append([]string{strconv.Itoa(k), "-", pcstime.FormatTime(file.Mtime), file.Filename + "/"})
continue
}
tb.Append([]string{strconv.Itoa(k), converter.ConvertFileSize(file.Size), pcstime.FormatTime(file.Mtime), file.Filename})
}
fN, dN = files.Count()
tb.Append([]string{"", "总: " + converter.ConvertFileSize(files.TotalSize()), "", fmt.Sprintf("文件总数: %d, 目录总数: %d", fN, dN)})
}
tb.Render()
if fN+dN >= 50 {
fmt.Printf("\n当前目录: %s\n", path)
}
fmt.Printf("----\n")
return
}