Skip to content
hakk
  • Home
  • Blog
  • Docs
  • DSA
  • Snippets

Time

  • Golang Listing Directory Contents and Sorting by File Modified Time 2020-06-09

    In this example we will be listing the contents of a directory in go and sorting by date.

    To get the list of files we will use the os.ReadDir function from the os package. This function returns a slice sorted by file name which contains elements of os.FileInfo type which will enable us to get the last modified time.

    To sort the files we will use the modification time with the sort package along with the After and Before functions from the time package.

Recent posts
  • Understanding the ss Command: A Modern Alternative to netstat
  • Understanding HTTP from Scratch with Python Sockets
  • When Environment Variables Mysteriously Reset...
  • How to Generate a 32-byte Key for AES Encryption
  • Streamlining Deployment: Installing Docker, Gitea, Gitea Act Runner, and Nginx on Ubuntu
© 2025 hakk
  • Home
  • Blog
  • Docs
  • DSA
  • Snippets