ReadDir in Go

Posted by GoDoc
Public (Editable by Users)

ReadDir reads the directory named by dirname and returns a list of directory entries sorted by filename.

Go
Edit
package main

import (
	"fmt"
	"io/ioutil"
	"log"
)

func main() {
	files, err := ioutil.ReadDir(".")
	if err != nil {
		log.Fatal(err)
	}

	for _, file := range files {
		fmt.Println(file.Name())
	}
}