project structure started
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
package eve
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"os/user"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func suffixTrim(s, suffix string) string {
|
||||
if strings.HasSuffix(s, suffix) {
|
||||
s = s[:len(s)-len(suffix)]
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
var filesFound []string
|
||||
var filesPotential []string
|
||||
var searchPath []string
|
||||
|
||||
func FileSearchUnix() []string {
|
||||
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")
|
||||
|
||||
userName, _ := user.Current()
|
||||
homeDir := userName.HomeDir
|
||||
|
||||
for _, d := range searchPath {
|
||||
|
||||
// if has trailing slash, remove it
|
||||
d = suffixTrim(d, "/")
|
||||
|
||||
// do a unix like expansion if the path starts like `~/`
|
||||
if strings.HasPrefix(d, "~/") {
|
||||
d = filepath.Join(homeDir, d[2:])
|
||||
}
|
||||
f, err := os.Open(d)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
files, err := f.Readdir(-1)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
err = f.Close()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
for _, file := range files {
|
||||
fullFilePath := fmt.Sprintf("%v/%v", d, file.Name())
|
||||
filesPotential = append(filesPotential, fullFilePath)
|
||||
}
|
||||
|
||||
}
|
||||
return filesPotential
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user