Skip to content

Commit

Permalink
Optimizing folder creation (#305)
Browse files Browse the repository at this point in the history
  • Loading branch information
binbin0325 authored Sep 11, 2021
1 parent 7863252 commit 9043c66
Showing 1 changed file with 6 additions and 28 deletions.
34 changes: 6 additions & 28 deletions common/file/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"os"
"path/filepath"
"runtime"
"strings"
)

var osType string
Expand All @@ -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
}

0 comments on commit 9043c66

Please sign in to comment.