From 86f51f1e4ac82c46ec691e5643037e99208c1257 Mon Sep 17 00:00:00 2001 From: john Date: Fri, 26 Jul 2019 23:01:12 +0800 Subject: [PATCH] improve gfile --- g/os/gfile/gfile.go | 15 ++++++++++++++- geg/other/test.go | 5 ++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/g/os/gfile/gfile.go b/g/os/gfile/gfile.go index 48db14a12..5be544322 100644 --- a/g/os/gfile/gfile.go +++ b/g/os/gfile/gfile.go @@ -375,13 +375,26 @@ func doScanDir(path string, pattern string, recursive ...bool) ([]string, error) // If it meets pattern, then add it to the result list. for _, p := range strings.Split(pattern, ",") { if match, err := filepath.Match(strings.TrimSpace(p), name); err == nil && match { - list = append(list, path) + path = Abs(path) + if path != "" { + list = append(list, path) + } } } } return list, nil } +// Abs returns an absolute representation of path. +// If the path is not absolute it will be joined with the current +// working directory to turn it into an absolute path. The absolute +// path name for a given file is not guaranteed to be unique. +// Abs calls Clean on the result. +func Abs(path string) string { + p, _ := filepath.Abs(path) + return p +} + // RealPath converts the given to its absolute path // and checks if the file path exists. // If the file does not exist, return an empty string. diff --git a/geg/other/test.go b/geg/other/test.go index 94e255909..c9ed507ac 100644 --- a/geg/other/test.go +++ b/geg/other/test.go @@ -2,10 +2,9 @@ package main import ( "fmt" - - "github.com/gogf/gf/g/os/gtime" + "path/filepath" ) func main() { - fmt.Println(gtime.Now().ISO8601()) + fmt.Println(filepath.Abs("s/s/s/s/s")) }