添加了使用函数CurrentDir

This commit is contained in:
李宇翔
2020-03-04 11:43:37 +08:00
parent acb9251b35
commit 898257b25b

View File

@@ -4,6 +4,8 @@ import (
"bufio" "bufio"
"io" "io"
"os" "os"
"path/filepath"
"runtime"
) )
// 检查文件或目录是否存在 // 检查文件或目录是否存在
@@ -38,3 +40,11 @@ func ReadFileLines(filename string) (lines []string, err error) {
return return
} }
func CurrentDir(path ...string) string {
_, currentFilePath, _, _ := runtime.Caller(1)
if len(path) == 0 {
return filepath.Dir(currentFilePath)
}
return filepath.Join(filepath.Dir(currentFilePath), filepath.Join(path...))
}