sync.go 746 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package main
  2. import (
  3. "fmt"
  4. "os"
  5. "git.wecise.com/wecise/util/filewalker"
  6. )
  7. // 同步指定文件夹中的内容
  8. func PrintUsage() {
  9. println(`Usage:
  10. sync <frompath> <topath>
  11. `)
  12. }
  13. func main() {
  14. var frompath, topath string
  15. if len(os.Args) > 2 {
  16. frompath = os.Args[1]
  17. topath = os.Args[2]
  18. }
  19. switch {
  20. case frompath != "" && topath != "":
  21. sync(frompath, topath)
  22. default:
  23. PrintUsage()
  24. os.Exit(1)
  25. }
  26. }
  27. func sync(frompath, topath string) {
  28. fw, err := filewalker.NewFileWalker([]string{frompath}, "") // orderby: dirfirst, filefirst, fullpath
  29. if err != nil {
  30. println(err.Error())
  31. }
  32. err = fw.List(func(basedir, fpath string) bool {
  33. fmt.Println(basedir, fpath)
  34. return true
  35. })
  36. if err != nil {
  37. println(err.Error())
  38. }
  39. }