use robocopy for copying and moving on windows

Mentioned in #12.
This commit is contained in:
Gokcehan 2017-07-25 19:37:16 +03:00
parent 74078f6111
commit d7fca734c8

25
nav.go
View File

@ -7,6 +7,7 @@ import (
"os"
"os/exec"
"path/filepath"
"runtime"
"sort"
"strings"
)
@ -512,16 +513,35 @@ func (nav *nav) put() error {
dir := nav.currDir()
var sh string
var args []string
var sh string
if runtime.GOOS == "windows" {
sh = "robocopy"
if !copy {
args = []string{"/move"}
}
for _, f := range list {
stat, err := os.Stat(f)
if err != nil {
log.Printf("getting file information: %s", err)
continue
}
base := filepath.Base(f)
dest := filepath.Dir(f)
if stat.IsDir() {
exec.Command(sh, append(args, f, filepath.Join(dir.path, base))...).Run()
} else {
exec.Command(sh, append(args, dest, dir.path, base)...).Run()
}
}
} else {
if copy {
sh = "cp"
args = append(args, "-r")
} else {
sh = "mv"
}
args = append(args, "--backup=numbered")
args = append(args, list...)
args = append(args, dir.path)
@ -531,6 +551,7 @@ func (nav *nav) put() error {
if err := cmd.Run(); err != nil {
return fmt.Errorf("%s: %s", sh, err)
}
}
// TODO: async?