mirror of
https://gitee.com/johng/gf
synced 2026-07-08 14:39:50 +08:00
improve gfile
This commit is contained in:
@ -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.
|
||||
|
||||
@ -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"))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user