Housekeeper/cmd/main.go

40 lines
645 B
Go
Raw Normal View History

2018-10-16 17:16:58 +00:00
package main
2018-10-16 20:06:46 +00:00
import (
"flag"
"fmt"
"log"
"os"
"path/filepath"
"time"
)
2018-10-16 17:16:58 +00:00
func main() {
2018-10-16 20:06:46 +00:00
var location string
var days int
flag.StringVar(&location, "location", "", "location to scan")
flag.IntVar(&days, "days", 0, "days to poll")
flag.Parse()
var files []string
err := filepath.Walk(location, func(path string, info os.FileInfo, err error) error {
files = append(files, path)
return nil
})
if err != nil {
log.Fatal(err)
}
now := time.Now()
cutoff := now.Add(-int(days * time.Hour)
fmt.Println(cutoff)
for _, file := range files {
if diff := now.Sub(files.ModTime()); diff > cutoff {
fmt.Println(diff)
}
}
2018-10-16 17:16:58 +00:00
}