forked from Angey40/BaiduPCS-Go
/
export.go
49 lines (41 loc) · 1 KB
/
export.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
package pcscommand
import (
"fmt"
"github.com/iikira/BaiduPCS-Go/baidupcs"
"path"
"strings"
)
// RunExport 执行导出文件和目录
func RunExport(pcspaths []string, rootPath string) {
pcspaths, err := getAllAbsPaths(pcspaths...)
if err != nil {
fmt.Println(err)
return
}
pcs := GetBaiduPCS()
for _, pcspath := range pcspaths {
getPath := func(p string) string {
if rootPath == "" {
return p
}
// 是一个单独文件
if pcspath == p {
return path.Join(rootPath, strings.TrimPrefix(p, path.Dir(pcspath)))
}
return path.Join(rootPath, strings.TrimPrefix(p, pcspath))
}
var d int
pcs.FilesDirectoriesRecurseList(pcspath, baidupcs.DefaultOrderOptions, func(depth int, fd *baidupcs.FileDirectory) {
if fd.Isdir {
if depth > d {
d = depth
} else {
fmt.Printf("BaiduPCS-Go mkdir \"%s\"\n", getPath(fd.Path))
d = 0
}
return
}
fmt.Printf("BaiduPCS-Go rapidupload -length=%d -md5=%s \"%s\"\n", fd.Size, fd.MD5, getPath(fd.Path))
})
}
}