Skip to content

Commit

Permalink
use system path separator for FilepathGlob
Browse files Browse the repository at this point in the history
  • Loading branch information
bmatcuk committed Jul 9, 2022
1 parent d581ef2 commit 40f387e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,8 @@ complication of io/fs. Basically, it:
* Creates an FS object from the base path and `Glob()s` on the pattern
* Joins the base path with all of the matches from `Glob()`
Unlike filepath.Glob, FilepathGlob will always return paths using `/` as the
path separator. If you want separators appropriate for your system, pass the
matches to `filepath.FromSlash()`.
Returned paths will use the system's path separator, just like
`filepath.Glob()`.
### SplitPattern
Expand Down
7 changes: 3 additions & 4 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,8 @@ func SplitPattern(p string) (base, pattern string) {
// * Creates an FS object from the base path and `Glob()s` on the pattern
// * Joins the base path with all of the matches from `Glob()`
//
// Unlike filepath.Glob, FilepathGlob will always return paths using `/` as the
// path separator. If you want separators appropriate for your system, pass the
// matches to `filepath.FromSlash()`.
// Returned paths will use the system's path separator, just like
// `filepath.Glob()`.
func FilepathGlob(pattern string) (matches []string, err error) {
pattern = filepath.Clean(pattern)
pattern = filepath.ToSlash(pattern)
Expand All @@ -87,7 +86,7 @@ func FilepathGlob(pattern string) (matches []string, err error) {
for i := range matches {
// use path.Join because we used ToSlash above to ensure our paths are made
// of forward slashes, no matter what the system uses
matches[i] = path.Join(base, matches[i])
matches[i] = filepath.FromSlash(path.Join(base, matches[i]))
}
return
}
Expand Down

0 comments on commit 40f387e

Please sign in to comment.