From e72437eff82197f156659144eb024ed130aa485e Mon Sep 17 00:00:00 2001 From: Alex Myasoedov Date: Thu, 18 Jan 2018 20:01:02 -0500 Subject: [PATCH] Add files utils --- files/query.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 files/query.go diff --git a/files/query.go b/files/query.go new file mode 100644 index 0000000..060474f --- /dev/null +++ b/files/query.go @@ -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 +}