Browse Source

change filepath

main
v_zhibsong 4 years ago
parent
commit
0bf0920486
  1. 27
      server/utils/file_operations.go

27
server/utils/file_operations.go

@ -3,7 +3,6 @@ package utils
import ( import (
"errors" "errors"
"fmt" "fmt"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
) )
@ -37,8 +36,8 @@ func FileMove(src string, dst string) error {
if err != nil { if err != nil {
return err return err
} }
if !oSrc.IsDir() {
return errors.New(fmt.Sprintf("%s is not Dir", src))
if oSrc.IsDir() {
return errors.New(fmt.Sprintf("%s is Dir", src))
} }
oDst, err := os.Stat(dst) oDst, err := os.Stat(dst)
if err != nil { if err != nil {
@ -47,15 +46,19 @@ func FileMove(src string, dst string) error {
if !oDst.IsDir() { if !oDst.IsDir() {
return errors.New(fmt.Sprintf("%s is not Dir", dst)) return errors.New(fmt.Sprintf("%s is not Dir", dst))
} }
// 遍历指定目录下所有文件
f, err := ioutil.ReadDir(src)
for _, file := range f {
nDst := filepath.Join(dst, file.Name())
nSrc := filepath.Join(src, file.Name())
err = fileMove(nSrc, nDst)
if err != nil {
return err
}
//// 遍历指定目录下所有文件
//f, err := ioutil.ReadDir(src)
//for _, file := range f {
// nDst := filepath.Join(dst, file.Name())
// nSrc := filepath.Join(src, file.Name())
// err = fileMove(nSrc, nDst)
// if err != nil {
// return err
// }
//}
err = fileMove(src, filepath.Join(dst, filepath.Base(dst)))
if err != nil {
return err
} }
return err return err
} }

Loading…
Cancel
Save