Go provides a directory iteration functionality out of the box, with filepath.Walk
in the path/filepath
package.
However, filepath.Walk
walks the file tree in lexical order. How can I walks the file tree in the order of last-modified date? Thx
PS (after accepting the answer) I think the Go filepath.Walk
function should provide a way for people to provide the sorting themselves, like the following answer, in which accepting type ByModTime
is all it take for people to sort the files themselves themselves.