Golang os.File.Readdir() function example

package os

Golang os.File.Readdir() function usage example

 dirname := "." + string(filepath.Separator)

 d, err := os.Open(dirname)
 if err != nil {
 fmt.Println(err)
 os.Exit(1)
 }
 defer d.Close()

 files, err := d.Readdir(-1)
 if err != nil {
 fmt.Println(err)
 os.Exit(1)
 }

See full examples at :

https://www.socketloop.com/tutorials/golang-read-directory-content-with-os-open

https://www.socketloop.com/tutorials/golang-copy-directory-including-sub-directories-files

References :

http://golang.org/pkg/os/#File.Readdir

Advertisement