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.
go-zero/tools/goctl/model/sql/util/matcher.go

39 lines
608 B
Go

package util
import (
"io/ioutil"
"path/filepath"
)
// expression: globbing patterns
func MatchFiles(in string) ([]string, error) {
dir, pattern := filepath.Split(in)
abs, err := filepath.Abs(dir)
if err != nil {
return nil, err
}
files, err := ioutil.ReadDir(abs)
if err != nil {
return nil, err
}
var res []string
for _, file := range files {
if file.IsDir() {
continue
}
name := file.Name()
match, err := filepath.Match(pattern, name)
if err != nil {
return nil, err
}
if !match {
continue
}
res = append(res, filepath.Join(abs, name))
}
return res, nil
}