From 40f387e34212ce0567ee49855b0e1a59ea9aa676 Mon Sep 17 00:00:00 2001 From: Bob Matcuk Date: Sat, 9 Jul 2022 18:50:17 -0400 Subject: [PATCH] use system path separator for FilepathGlob --- README.md | 5 ++--- utils.go | 7 +++---- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 791e0be..2b17180 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/utils.go b/utils.go index cc3839b..d4d2cc1 100644 --- a/utils.go +++ b/utils.go @@ -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) @@ -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 }