Generate a list of files / directories in a directory in Go
Import the package as
import "github.com/pmirshad/file_list"
Invoke the function as
files := file_list.AllFiles("/home/pmirshad", true)
AllFiles returns a slice of type file_list.FileInfo
The first argument to the sort functions is a reference to the slice to be sorted. The second argument is a bool
which decides whether the list is sorted in reverse order.
-
By modification time
file_list.SortByModTime(&files, false)
-
By name
file_list.SortByName(&files, false)
-
By size
file_list.SortBySize(&files, false)
type FileInfo struct {
AbsPath string // absolute path for the file
Name string // base name of the file
Size int64 // length in bytes for regular files
Mode os.FileMode // file mode bits
ModTime time.Time // modification time
IsDir bool // abbreviation for Mode().IsDir()
}