cdhist/dir/dir.go

37 lines
571 B
Go

package dir
import (
"os"
// "errors"
"path/filepath"
"strings"
)
func Exist(path string) bool {
if _, err := os.Stat(path); os.IsNotExist(err) {
return false
}
return true
}
func Sanitize(path string) (string, error) {
switch path {
case "-":
path = os.Getenv("OLDPWD")
case "":
var err error // need to do this because the next line won't work using :=
path, err = os.UserHomeDir()
if err != nil {
return "", err
}
}
path = strings.TrimSpace(path)
path, err := filepath.Abs(path)
if err != nil {
return "", err
}
return path, nil
}