Add files utils
This commit is contained in:
parent
ce0bc9118b
commit
e72437eff8
1 changed files with 25 additions and 0 deletions
25
files/query.go
Normal file
25
files/query.go
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
package files
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io/ioutil"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
var epoch = time.Unix(1494505756, 0)
|
||||||
|
|
||||||
|
func LatestFileIn(path string) (latest string) {
|
||||||
|
files, err := ioutil.ReadDir(path)
|
||||||
|
if err != nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
latestTime := epoch
|
||||||
|
for _, f := range files {
|
||||||
|
path := f.Name()
|
||||||
|
pathModifiedAt := f.ModTime()
|
||||||
|
if pathModifiedAt.After(latestTime) {
|
||||||
|
latestTime = pathModifiedAt
|
||||||
|
latest = path
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
Loading…
Reference in a new issue