Skip to content

Instantly share code, notes, and snippets.

@vaguecoder
Last active May 21, 2021 19:10
Show Gist options
  • Save vaguecoder/f4ad2a875464e05bc16ac8ef88d79067 to your computer and use it in GitHub Desktop.
Save vaguecoder/f4ad2a875464e05bc16ac8ef88d79067 to your computer and use it in GitHub Desktop.
This filters out the list of files/directories in the given window. More details in: https://github.com/VagueCoder/Random-Go-Snippets/
package main
import (
"fmt"
"io/ioutil"
"time"
)
func main() {
// Not handling any errors since just demonstration
start, _ := time.Parse("02-Jan-2006 15:04:05 MST", "12-May-2021 17:00:00 IST")
end, _ := time.Parse("02-Jan-2006 15:04:05 MST", "12-May-2021 18:00:00 IST")
files, _ := ioutil.ReadDir("folder")
for _, file := range files {
modifiedTime := file.ModTime()
if modifiedTime.After(start) && modifiedTime.Before(end) {
// Better to store the file instead of printing the filename
fmt.Println(file.Name())
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment