-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.go
More file actions
56 lines (50 loc) · 1.16 KB
/
utils.go
File metadata and controls
56 lines (50 loc) · 1.16 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package main
import (
"io/ioutil"
"log"
"os"
"strings"
)
func ProgramInPath(program string, logExes bool) bool {
for _, path := range Paths {
if strings.HasSuffix(path, ".exe") || !DirExists(path, false) { // if its not a folder or it also doesnt exist
continue
}
files, err := ioutil.ReadDir(path)
if err != nil {
log.Fatal(err)
}
for _, file := range files { // over each file
if strings.HasSuffix(file.Name(), ".exe") {
if logExes {
Yellow.Printf("%s\n", file.Name())
}
if file.Name() == program {
ProgramPath = path
return true
}
}
}
}
return false
}
func DirExists(path string, log bool) bool {
if _, err := os.Stat(path); os.IsNotExist(err) {
if log {
Red.Printf("Directory \"%s\" does not exist!", path)
}
return false
}
return true
}
func ValidateDir(originalDir []string) {
if !DirExists(CurDir, true) {
// If directory exists, add it to the Paths array
CurDir = strings.Join(originalDir, "\\")
Paths = Paths[:len(Paths)-1]
Paths = append(Paths, strings.TrimSuffix(CurDir, "\n"))
}
}
func TrimLineEnd(str string) string {
return strings.TrimSuffix(strings.TrimSuffix(str, "\n"), "\r")
}