-
Notifications
You must be signed in to change notification settings - Fork 12
/
sort.go
51 lines (43 loc) · 1.03 KB
/
sort.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright 2021 The searKing Author. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package os
import "os"
// sort filename by mode time in increase order
type FileModeTimeSlice []string
func (s FileModeTimeSlice) Len() int {
return len(s)
}
func (s FileModeTimeSlice) Swap(i, j int) {
s[i], s[j] = s[j], s[i]
}
func (s FileModeTimeSlice) Less(i, j int) bool {
fi, err := os.Stat(s[i])
if err != nil {
return false
}
fj, err := os.Stat(s[j])
if err != nil {
return false
}
return fi.ModTime().Before(fj.ModTime())
}
// sort filename by mode time in decrease order
type FileModeTimeDescSlice []string
func (s FileModeTimeDescSlice) Len() int {
return len(s)
}
func (s FileModeTimeDescSlice) Swap(i, j int) {
s[i], s[j] = s[j], s[i]
}
func (s FileModeTimeDescSlice) Less(i, j int) bool {
fi, err := os.Stat(s[i])
if err != nil {
return false
}
fj, err := os.Stat(s[j])
if err != nil {
return false
}
return fi.ModTime().After(fj.ModTime())
}