✏️ 尝试解决win下路径异常

This commit is contained in:
fumiama
2021-10-24 18:13:12 +08:00
parent 3a5e391191
commit a3685e2e83
8 changed files with 49 additions and 22 deletions

11
utils/file/dir_nowin.go Normal file
View File

@@ -0,0 +1,11 @@
//go:build !windows
// +build !windows
package file
import "os"
func Pwd() (path string) {
path, _ = os.Getwd()
return
}

14
utils/file/dir_win.go Normal file
View File

@@ -0,0 +1,14 @@
//go:build windows
// +build windows
package file
import (
"os"
"strings"
)
func Pwd() string {
path, _ := os.Getwd()
return strings.ReplaceAll(path, "\\", "/")
}

View File

@@ -21,15 +21,3 @@ func DownloadTo(url, file string) error {
}
return err
}
// IsExist 文件/路径存在
func IsExist(path string) bool {
_, err := os.Stat(path)
return err == nil || os.IsExist(err)
}
// IsExist 文件/路径不存在
func IsNotExist(path string) bool {
_, err := os.Stat(path)
return err != nil && os.IsNotExist(err)
}

17
utils/file/f.go Normal file
View File

@@ -0,0 +1,17 @@
package file
import "os"
var BOT_PATH = Pwd()
// IsExist 文件/路径存在
func IsExist(path string) bool {
_, err := os.Stat(path)
return err == nil || os.IsExist(err)
}
// IsExist 文件/路径不存在
func IsNotExist(path string) bool {
_, err := os.Stat(path)
return err != nil && os.IsNotExist(err)
}