From 254933c2f00eb47831da3156e8dac3b1cb5ebdb8 Mon Sep 17 00:00:00 2001 From: Matt Burchett Date: Wed, 17 Oct 2018 14:40:19 -0500 Subject: [PATCH] stuff and thangs --- cmd/main.go | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/cmd/main.go b/cmd/main.go index 965253f..effdf16 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -10,11 +10,10 @@ import ( ) func isOlder(t time.Time, days int) bool { - hours := time.Duration(days*24) * time.Hour - return time.Now().Sub(t) > hours*time.Hour + return time.Now().Sub(t) > 1*time.Hour } -func getFiles(location string, days int) error { +func getFiles(location string, days int) ([]string, error) { var files []string err := filepath.Walk(location, func(path string, info os.FileInfo, err error) error { files = append(files, path) @@ -24,11 +23,20 @@ func getFiles(location string, days int) error { log.Fatal(err) } + test := make([]string, 0) + for _, file := range files { - fmt.Println(file) + at, err := os.Stat(file) + if err != nil { + log.Fatal(err) + } + if isOlder(at.ModTime(), days) { + test = append(test, file) + } + } - return err + return test, err } @@ -39,6 +47,13 @@ func main() { flag.IntVar(&days, "days", 0, "days to poll") flag.Parse() - _ = getFiles(location, days) + files, err := getFiles(location, days) + if err != nil { + log.Fatal(err) + } + + for _, file := range files { + fmt.Println(file) + } }