summaryrefslogtreecommitdiffstats
path: root/hugolib/path.go
blob: 03a5dba041fe1bb45f91565e3caf22463434da50 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package hugolib

import (
	"os"
	"strings"
)

func fileExt(path string) (file, ext string) {
	if strings.Contains(path, ".") {
		i := len(path) - 1
		for path[i] != '.' {
			i--
		}
		return path[:i], path[i+1:]
	}
	return path, ""
}

func replaceExtension(path string, newExt string) string {
	f, _ := fileExt(path)
	return f + "." + newExt
}

// Check if Exists && is Directory
func dirExists(path string) (bool, error) {
	fi, err := os.Stat(path)
	if err == nil && fi.IsDir() {
		return true, nil
	}
	if os.IsNotExist(err) {
		return false, nil
	}
	return false, err
}