go-root-dir/root_dir.go

21 lines
366 B
Go
Raw Normal View History

2023-03-11 12:38:51 +01:00
package root_dir
2023-02-26 09:35:06 +01:00
import (
2023-03-11 12:26:02 +01:00
"os"
"regexp"
2023-02-26 09:35:06 +01:00
)
2023-03-11 12:26:02 +01:00
func RootDir(projectDirName string) string {
if projectDirName == "" {
2023-02-26 09:35:06 +01:00
return ""
}
2023-03-11 12:26:02 +01:00
projectName := regexp.MustCompile(`^(.*` + projectDirName + `)`)
currentWorkDirectory, _ := os.Getwd()
rootPath := projectName.Find([]byte(currentWorkDirectory))
if len(rootPath) <= 0 {
return ""
}
return string(rootPath)
2023-02-26 09:35:06 +01:00
}