Skip to content
This repository was archived by the owner on Sep 23, 2021. It is now read-only.

Commit e72437e

Browse files
committed
Add files utils
1 parent ce0bc91 commit e72437e

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

files/query.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package files
2+
3+
import (
4+
"io/ioutil"
5+
"time"
6+
)
7+
8+
var epoch = time.Unix(1494505756, 0)
9+
10+
func LatestFileIn(path string) (latest string) {
11+
files, err := ioutil.ReadDir(path)
12+
if err != nil {
13+
return ""
14+
}
15+
latestTime := epoch
16+
for _, f := range files {
17+
path := f.Name()
18+
pathModifiedAt := f.ModTime()
19+
if pathModifiedAt.After(latestTime) {
20+
latestTime = pathModifiedAt
21+
latest = path
22+
}
23+
}
24+
return
25+
}

0 commit comments

Comments
 (0)