2016-11-15 16:23:20 +01:00
|
|
|
package goutil
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"path/filepath"
|
2016-11-19 00:55:13 +01:00
|
|
|
"strings"
|
2016-11-15 16:23:20 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func WriteFile(filename string, data string) error {
|
|
|
|
return ioutil.WriteFile(filename, []byte(data), 0644)
|
|
|
|
}
|
|
|
|
|
|
|
|
func ReadFile(filename string) (string, error) {
|
|
|
|
data, err := ioutil.ReadFile(filename)
|
|
|
|
return string(data), err
|
|
|
|
}
|
|
|
|
|
|
|
|
func TrimExt(path string) string {
|
|
|
|
extension := filepath.Ext(path)
|
|
|
|
return path[0 : len(path)-len(extension)]
|
|
|
|
}
|
2016-11-19 00:55:13 +01:00
|
|
|
|
|
|
|
func ListFilesExt(dir string, ext string) []string {
|
|
|
|
list := make([]string, 0)
|
|
|
|
ext = strings.ToUpper(ext)
|
|
|
|
files, err := ioutil.ReadDir(dir)
|
|
|
|
if err == nil {
|
|
|
|
for _, file := range files {
|
|
|
|
if !file.IsDir() {
|
|
|
|
if strings.ToUpper(filepath.Ext(file.Name())) == ext {
|
|
|
|
list = append(list, file.Name())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return list
|
|
|
|
}
|