improve gfile

This commit is contained in:
john
2019-07-26 23:01:12 +08:00
parent 622f76d5fb
commit 86f51f1e4a
2 changed files with 16 additions and 4 deletions

View File

@ -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 <path> to its absolute path
// and checks if the file path exists.
// If the file does not exist, return an empty string.

View File

@ -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"))
}