2024-06-18 18:21:03 -04:00
|
|
|
// Package files finds and displays files on disk
|
|
|
|
package files
|
|
|
|
|
2024-07-03 18:05:17 -04:00
|
|
|
import "time"
|
|
|
|
|
|
|
|
type File interface {
|
|
|
|
Name() string
|
|
|
|
Path() string
|
|
|
|
Date() time.Time
|
|
|
|
Filesize() int64
|
|
|
|
IsDir() bool
|
2024-06-18 18:21:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
type Files []File
|
|
|
|
|
2024-07-03 18:05:17 -04:00
|
|
|
func SortByModified(a, b File) int {
|
|
|
|
if a.Date().After(b.Date()) {
|
|
|
|
return 1
|
|
|
|
} else if a.Date().Before(b.Date()) {
|
|
|
|
return -1
|
2024-06-18 18:21:03 -04:00
|
|
|
} else {
|
2024-07-03 18:05:17 -04:00
|
|
|
return 0
|
2024-06-18 18:21:03 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-03 18:05:17 -04:00
|
|
|
func SortByModifiedReverse(a, b File) int {
|
|
|
|
if a.Date().Before(b.Date()) {
|
|
|
|
return 1
|
|
|
|
} else if a.Date().After(b.Date()) {
|
|
|
|
return -1
|
|
|
|
} else {
|
|
|
|
return 0
|
2024-06-19 23:25:04 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-03 18:05:17 -04:00
|
|
|
func SortBySize(a, b File) int {
|
|
|
|
if a.Filesize() > b.Filesize() {
|
|
|
|
return 1
|
|
|
|
} else if a.Filesize() < b.Filesize() {
|
|
|
|
return -1
|
|
|
|
} else {
|
|
|
|
return 0
|
2024-06-18 18:21:03 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-03 18:05:17 -04:00
|
|
|
func SortBySizeReverse(a, b File) int {
|
|
|
|
if a.Filesize() < b.Filesize() {
|
|
|
|
return 1
|
|
|
|
} else if a.Filesize() > b.Filesize() {
|
|
|
|
return -1
|
|
|
|
} else {
|
|
|
|
return 0
|
2024-06-18 18:21:03 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-03 18:05:17 -04:00
|
|
|
func SortByName(a, b File) int {
|
|
|
|
if a.Name() > b.Name() {
|
2024-06-18 18:21:03 -04:00
|
|
|
return 1
|
2024-07-03 18:05:17 -04:00
|
|
|
} else if a.Name() < b.Name() {
|
2024-06-18 18:21:03 -04:00
|
|
|
return -1
|
|
|
|
} else {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-03 18:05:17 -04:00
|
|
|
func SortByNameReverse(a, b File) int {
|
|
|
|
if a.Name() < b.Name() {
|
2024-06-18 18:21:03 -04:00
|
|
|
return 1
|
2024-07-03 18:05:17 -04:00
|
|
|
} else if a.Name() > b.Name() {
|
2024-06-18 18:21:03 -04:00
|
|
|
return -1
|
|
|
|
} else {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-03 18:05:17 -04:00
|
|
|
func SortByPath(a, b File) int {
|
|
|
|
if a.Path() > b.Path() {
|
2024-06-18 18:21:03 -04:00
|
|
|
return 1
|
2024-07-03 18:05:17 -04:00
|
|
|
} else if a.Path() < b.Path() {
|
2024-06-18 18:21:03 -04:00
|
|
|
return -1
|
|
|
|
} else {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-03 18:05:17 -04:00
|
|
|
func SortByPathReverse(a, b File) int {
|
|
|
|
if a.Path() < b.Path() {
|
2024-06-18 18:21:03 -04:00
|
|
|
return 1
|
2024-07-03 18:05:17 -04:00
|
|
|
} else if a.Path() > b.Path() {
|
2024-06-18 18:21:03 -04:00
|
|
|
return -1
|
|
|
|
} else {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
}
|