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
  • How to Update a File's Creation Time in PowerShell
  • How to Run PowerShell Code Only During Certain Times
  • PeopleSoft App Server Freeze Troubleshooting Checklist
  • Build Vim With Python3 Support
  • Understanding the ss Command: A Modern Alternative to netstat
© 2026 hakk
  • Home
  • Blog
  • Docs
  • DSA
  • Snippets