/
path.go
executable file
·35 lines (30 loc) · 941 Bytes
/
path.go
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
35
package pathhelper
import (
"fmt"
"os"
"path/filepath"
"runtime"
"github.com/mitchellh/go-homedir"
)
// HomeDir calls homedir.Dir() but changes the backslashes with forwardslashes
// on Windows.
func HomeDir() (string, error) {
homedir, err := homedir.Dir()
if err != nil {
return "", fmt.Errorf("pathhelper.HomeDir: %s", err.Error())
}
// ToSlash replaces \ with /. The opposite is filepath.FromSlash(string)
return filepath.ToSlash(homedir), nil
}
// DesktopPath returns the path to Desktop on a Windows machine.
func DesktopPath() (string, error) {
if runtime.GOOS != "windows" {
return "", fmt.Errorf("pathhelper.DesktopPath: not running Windows, running %s", runtime.GOOS)
}
home, err := HomeDir()
return filepath.Join(home, "Desktop"), err
}
// DeletePath deletes a path and all its children from disk.
func DeletePath(pathname string) error {
return os.RemoveAll(pathname)
}