Read directory

This is an example Go program for read-directory.

package main

import (
        "fmt"
        "os"
)

func main() {
        dir := "."
        entries, err := os.ReadDir(dir)
        if err != nil {
                fmt.Fprintf(os.Stderr, "Fatal error reading %s: %s\n", dir, err)
                os.Exit(1)
        }
        for _, entry := range entries {
                fmt.Printf("%s\n", entry.Name())
        }
}

(download)

The output of the example looks like this:

.gitignore
index.html
links-table
makefile
rd
rd.go
rd.go.~1~
rd.txt
tags


Copyright © Ben Bullock 2009-2024. All rights reserved. For comments, questions, and corrections, please email Ben Bullock (benkasminbullock@gmail.com) or use the discussion group at Google Groups. / Privacy / Disclaimer