Skip to content

Commit

Permalink
👔 up: fsutil add const and update the FindInDir()
Browse files Browse the repository at this point in the history
- timex add some new const for sec time
  • Loading branch information
inhere committed Apr 21, 2024
1 parent dce0f0b commit 0f525a0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
9 changes: 6 additions & 3 deletions fsutil/find.go
Expand Up @@ -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()

Expand Down
3 changes: 3 additions & 0 deletions fsutil/fsutil.go
Expand Up @@ -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...)
Expand Down
8 changes: 7 additions & 1 deletion timex/timex.go
Expand Up @@ -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
Expand All @@ -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

Expand Down

0 comments on commit 0f525a0

Please sign in to comment.