1 Star 0 Fork 0

marcello/go-common

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
path.go 687 Bytes
一键复制 编辑 原始数据 按行查看 历史
marcello 提交于 2021-05-16 20:33 +08:00 . -
package base
import (
"os"
"path/filepath"
"runtime"
"strings"
)
// PathExists 判断目录或者文件是否存在
func PathExists(path string) (bool, error) {
_, err := os.Stat(path)
if err == nil {
return true, nil
}
if os.IsNotExist(err) {
return false, nil
}
return false, err
}
// GetCurrentDirectory 返回工作目录
func GetCurrentDirectory() string {
dir, err := filepath.Abs(filepath.Dir(os.Args[0])) //返回绝对路径 filepath.Dir(os.Args[0])去除最后一个元素的路径
if err != nil {
return ""
}
if runtime.GOOS == "windows" {
// 只有windows需要替换
return strings.Replace(dir, "\\", "/", -1) //将\替换成/
}
return dir
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/marcellos/go-common.git
git@gitee.com:marcellos/go-common.git
marcellos
go-common
go-common
e809a504da49

搜索帮助