diff --git a/common/file/file.go b/common/file/file.go index db307721..10f3efeb 100644 --- a/common/file/file.go +++ b/common/file/file.go @@ -21,7 +21,6 @@ import ( "os" "path/filepath" "runtime" - "strings" ) var osType string @@ -39,37 +38,16 @@ func init() { } func MkdirIfNecessary(createDir string) (err error) { - s := strings.Split(createDir, path) - startIndex := 0 - dir := "" - if s[0] == "" { - startIndex = 1 - } else { - dir, _ = os.Getwd() //当前的目录 - } - for i := startIndex; i < len(s); i++ { - var d string - if osType == WINDOWS && filepath.IsAbs(createDir) { - d = strings.Join(s[startIndex:i+1], path) - } else { - d = dir + path + strings.Join(s[startIndex:i+1], path) - } - if _, e := os.Stat(d); os.IsNotExist(e) { - err = os.Mkdir(d, os.ModePerm) //在当前目录下生成md目录 - if err != nil { - break - } - } - } - - return err + return os.MkdirAll(createDir, os.ModePerm) } func GetCurrentPath() string { - - dir, err := filepath.Abs(filepath.Dir(os.Args[0])) + dir, err := os.Getwd() //当前的目录 if err != nil { - log.Println("can not get current path") + dir, err = filepath.Abs(filepath.Dir(os.Args[0])) + if err != nil { + log.Println("can not get current path") + } } return dir }