package main import ( "fmt" "os" ) func main() { dirName := "." files, err := os.Readdirnames(dirName) if err != nil { fmt.Println(err) return } for _, fileName := range files { fmt.Println(fileName) } }
package main import ( "fmt" "os" "strings" ) func main() { dirName := "." files, err := os.Readdirnames(dirName) if err != nil { fmt.Println(err) return } for _, fileName := range files { if strings.HasSuffix(fileName, ".go") { fmt.Println(fileName) } } }This example shows how to filter the files based on their extension. The program only prints the names of files with the extension `.go`. The `os` package is a built-in package in Go.