mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2026-02-12 02:00:24 +00:00
✏️ 尝试解决win下路径异常
This commit is contained in:
11
utils/file/dir_nowin.go
Normal file
11
utils/file/dir_nowin.go
Normal 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
14
utils/file/dir_win.go
Normal 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, "\\", "/")
|
||||
}
|
||||
@@ -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
17
utils/file/f.go
Normal 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)
|
||||
}
|
||||
Reference in New Issue
Block a user