You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
73 lines
1.2 KiB
Go
73 lines
1.2 KiB
Go
package mercuryUtil
|
|
|
|
import (
|
|
"encoding/csv"
|
|
"fmt"
|
|
"os"
|
|
"path"
|
|
)
|
|
|
|
func GetAllFilesInDir(pathlikeBase string) (*[]string, error) {
|
|
listing, err := os.ReadDir(pathlikeBase)
|
|
res := make([]string, 0, 300)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
for _, list := range listing {
|
|
if list.IsDir() || path.Ext(list.Name()) != ".csv" {
|
|
fmt.Printf("Skipping: %s\n", list.Name())
|
|
continue
|
|
} else {
|
|
res = append(res, path.Join(pathlikeBase, list.Name()))
|
|
}
|
|
}
|
|
return &res, nil
|
|
}
|
|
|
|
func CopyFile(inPath string, outpath string) error {
|
|
b, err := os.ReadFile(inPath)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
err = os.WriteFile(outpath, b, 0755)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func LoadCsv(pathlike string) (*[][]string, error) {
|
|
f, err := os.OpenFile(pathlike, os.O_RDONLY, 0755)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
defer f.Close()
|
|
|
|
reader := csv.NewReader(f)
|
|
|
|
records, err := reader.ReadAll()
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &records, nil
|
|
}
|
|
|
|
func StringArrEquals(a []string, b []string) bool {
|
|
if len(a) != len(b) {
|
|
return false
|
|
}
|
|
//should we do this? it screws up order independence
|
|
//sort.Strings(a)
|
|
//sort.Strings(b)
|
|
|
|
for i := 0; i < len(a); i++ {
|
|
vA := a[i]
|
|
vB := b[i]
|
|
if vA != vB {
|
|
return false
|
|
}
|
|
}
|
|
return true
|
|
}
|