GlobPaths expands a list of file patterns into a list of file paths. If no files match a pattern, that pattern will return an error. If no pattern is passed, this returns an empty list and no error. For information on supported glob patterns, see https://pkg.go.dev/path/filepath#Match
(patterns []string)
| 83 | // For information on supported glob patterns, see |
| 84 | // https://pkg.go.dev/path/filepath#Match |
| 85 | func GlobPaths(patterns []string) ([]string, error) { |
| 86 | expansions := []string{} |
| 87 | |
| 88 | for _, pattern := range patterns { |
| 89 | matches, err := filepath.Glob(pattern) |
| 90 | if err != nil { |
| 91 | return nil, fmt.Errorf("%s: %v", pattern, err) |
| 92 | } |
| 93 | if len(matches) == 0 { |
| 94 | return []string{}, fmt.Errorf("no matches found for `%s`", pattern) |
| 95 | } |
| 96 | expansions = append(expansions, matches...) |
| 97 | } |
| 98 | |
| 99 | return expansions, nil |
| 100 | } |