This commit is contained in:
2019-12-09 18:23:48 +00:00
parent 17e2bfe2bb
commit d2803affc1
3 changed files with 53 additions and 0 deletions
+51
View File
@@ -0,0 +1,51 @@
package main
import (
"fmt"
"log"
"os"
"os/user"
"path/filepath"
"strings"
)
func TrimSuffix(s, suffix string) string {
if strings.HasSuffix(s, suffix) {
s = s[:len(s)-len(suffix)]
}
return s
}
func main() {
var searchPath []string
searchPath = append(searchPath,
"/home/starkers/.local/share/Steam/steamapps/compatdata/8500/pfx/drive_c/users/steamuser/My Documents/EVE/logs/Chatlogs")
usr, _ := user.Current()
dir := usr.HomeDir
for _, d := range searchPath {
// if has trailing slash, remove it
d = TrimSuffix(d, "/")
// do a unix like expansion if the path starts like `~/`
if strings.HasPrefix(d, "~/") {
d = filepath.Join(dir, d[2:])
}
f, err := os.Open(d)
if err != nil {
log.Fatal(err)
}
files, err := f.Readdir(-1)
f.Close()
if err != nil {
log.Fatal(err)
}
for _, file := range files {
fmt.Printf("%v/%v\n", d, file.Name())
}
}
}