30 lines
532 B
Go
30 lines
532 B
Go
package util
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"path/filepath"
|
|
"strings"
|
|
)
|
|
|
|
// DirByExt returns entries in a directory with the specified extension
|
|
func DirByExt(dir, ext string) ([]string, error) {
|
|
fis, err := ioutil.ReadDir(dir)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
out := make([]string, 0, len(fis))
|
|
|
|
for _, fi := range fis {
|
|
relname := fi.Name()
|
|
extname := filepath.Ext(relname)
|
|
|
|
// Skip anything that doesn't match the extension
|
|
if strings.EqualFold(extname, ext) {
|
|
out = append(out, relname)
|
|
}
|
|
}
|
|
|
|
return out, nil
|
|
}
|