software development, devops, and other drivel
Tree lined path


Golang Listing Directory Contents and Sorting by File Modified Time

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. Read more...