|
|
@@ -14,20 +14,36 @@ import (
|
|
|
* @param srcPath 需要拷贝的文件夹路径: D:/test
|
|
|
* @param destPath 拷贝到的位置: D:/backup/
|
|
|
*/
|
|
|
-func CopyDir(srcPath1 string, destPath1 string) error {
|
|
|
- srcPath := strings.Replace(srcPath1, "\\", "/", -1)
|
|
|
- destPath := strings.Replace(destPath1, "\\", "/", -1)
|
|
|
- //检测目录正确性
|
|
|
- if srcInfo, err := os.Stat(srcPath); err != nil {
|
|
|
- fmt.Println(err.Error())
|
|
|
- return err
|
|
|
- } else {
|
|
|
+func CopyDir(path ...string) error {
|
|
|
+ if len(path) < 2 {
|
|
|
+ return errors.New("args illegal")
|
|
|
+ }
|
|
|
+ srcPath := ""
|
|
|
+ for i := 0; i < len(path)-1; i++ {
|
|
|
+ srcPath1 := path[i]
|
|
|
+ srcPath = strings.Replace(srcPath1, "\\", "/", -1)
|
|
|
+ srcInfo, err := os.Stat(srcPath)
|
|
|
+ //检测目录正确性
|
|
|
+ if err != nil {
|
|
|
+ srcPath = ""
|
|
|
+ continue
|
|
|
+ }
|
|
|
if !srcInfo.IsDir() {
|
|
|
- e := errors.New("srcPath不是一个正确的目录!")
|
|
|
- fmt.Println(e.Error())
|
|
|
- return e
|
|
|
+ srcPath = ""
|
|
|
+ } else {
|
|
|
+ break
|
|
|
}
|
|
|
}
|
|
|
+ if srcPath == "" {
|
|
|
+ err := fmt.Errorf("src path %v error", path[:len(path)-1])
|
|
|
+ fmt.Println(err.Error())
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ destPath1 := ""
|
|
|
+ if len(path) >= 2 {
|
|
|
+ destPath1 = path[len(path)-1]
|
|
|
+ }
|
|
|
+ destPath := strings.Replace(destPath1, "\\", "/", -1)
|
|
|
if destInfo, err := os.Stat(destPath); err != nil {
|
|
|
fmt.Println(err.Error())
|
|
|
return err
|