From 0f525a09636d2fce0640c2a9dc3c0221023efd59 Mon Sep 17 00:00:00 2001 From: Inhere Date: Sun, 21 Apr 2024 11:13:31 +0800 Subject: [PATCH] :necktie: up: fsutil add const and update the FindInDir() - timex add some new const for sec time --- fsutil/find.go | 9 ++++++--- fsutil/fsutil.go | 3 +++ timex/timex.go | 8 +++++++- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/fsutil/find.go b/fsutil/find.go index 19ab7f585..1f563f059 100644 --- a/fsutil/find.go +++ b/fsutil/find.go @@ -216,14 +216,17 @@ func FindInDir(dir string, handleFn HandleFunc, filters ...FilterFunc) (e error) return // ignore I/O error } - // names, _ := d.Readdirnames(-1) - // sort.Strings(names) - des, err := os.ReadDir(dir) if err != nil { return } + // remove the last '/' char + dirLn := len(dir) + if dirLn > 1 && dir[dirLn-1] == '/' { + dir = dir[:dirLn-1] + } + for _, ent := range des { filePath := dir + "/" + ent.Name() diff --git a/fsutil/fsutil.go b/fsutil/fsutil.go index d471fc2e8..0eabd6fc4 100644 --- a/fsutil/fsutil.go +++ b/fsutil/fsutil.go @@ -10,6 +10,9 @@ import ( "github.com/gookit/goutil/internal/comfunc" ) +// PathSep alias of os.PathSeparator +const PathSep = os.PathSeparator + // JoinPaths elements, alias of filepath.Join() func JoinPaths(elem ...string) string { return filepath.Join(elem...) diff --git a/timex/timex.go b/timex/timex.go index 74027d5b2..48e63efd7 100644 --- a/timex/timex.go +++ b/timex/timex.go @@ -11,7 +11,7 @@ import ( "github.com/gookit/goutil/strutil" ) -// provide some commonly time consts +// provide some commonly time constants const ( OneSecond = 1 OneMinSec = 60 @@ -20,6 +20,12 @@ const ( OneWeekSec = 7 * 86400 OneMonthSec = 30 * 86400 + MinSec = OneMinSec + HourSec = OneHourSec + DaySec = OneDaySec + WeekSec = OneWeekSec + MonthSec = OneMonthSec + Microsecond = time.Microsecond Millisecond = time.Millisecond