strings.trimSuffix does the job for you already
This commit is contained in:
+2
-10
@@ -9,13 +9,6 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func suffixTrim(s, suffix string) string {
|
|
||||||
if strings.HasSuffix(s, suffix) {
|
|
||||||
s = s[:len(s)-len(suffix)]
|
|
||||||
}
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
|
|
||||||
var filesFound []string
|
var filesFound []string
|
||||||
var filesPotential []string
|
var filesPotential []string
|
||||||
var searchPath []string
|
var searchPath []string
|
||||||
@@ -24,14 +17,13 @@ func FileSearchUnix() []string {
|
|||||||
fmt.Println("looking for chat log files..")
|
fmt.Println("looking for chat log files..")
|
||||||
|
|
||||||
searchPath = append(searchPath, "~/.local/share/Steam/steamapps/compatdata/8500/pfx/drive_c/users/steamuser/My Documents/EVE/logs/Chatlogs")
|
searchPath = append(searchPath, "~/.local/share/Steam/steamapps/compatdata/8500/pfx/drive_c/users/steamuser/My Documents/EVE/logs/Chatlogs")
|
||||||
|
|
||||||
userName, _ := user.Current()
|
userName, _ := user.Current()
|
||||||
homeDir := userName.HomeDir
|
homeDir := userName.HomeDir
|
||||||
|
|
||||||
for _, d := range searchPath {
|
for _, d := range searchPath {
|
||||||
|
|
||||||
// if has trailing slash, remove it
|
// if has trailing slash, remove it
|
||||||
d = suffixTrim(d, "/")
|
d = strings.TrimSuffix(d, "/")
|
||||||
|
|
||||||
// do a unix like expansion if the path starts like `~/`
|
// do a unix like expansion if the path starts like `~/`
|
||||||
if strings.HasPrefix(d, "~/") {
|
if strings.HasPrefix(d, "~/") {
|
||||||
@@ -72,7 +64,7 @@ func PathSearch() []string {
|
|||||||
for _, d := range searchPath {
|
for _, d := range searchPath {
|
||||||
|
|
||||||
// if has trailing slash, remove it
|
// if has trailing slash, remove it
|
||||||
d = suffixTrim(d, "/")
|
d = strings.TrimSuffix(d, "/")
|
||||||
|
|
||||||
// do a unix like expansion if the path starts like `~/`
|
// do a unix like expansion if the path starts like `~/`
|
||||||
if strings.HasPrefix(d, "~/") {
|
if strings.HasPrefix(d, "~/") {
|
||||||
|
|||||||
Reference in New Issue
Block a user