PHP » GoLang |
login |
register |
about
|
dirdir[code=golang]
import (
"os"
)
// dir lists the contents of a directory
func dir(path string) ([]os.FileInfo, error) {
// Open the directory using os.Open
dir, err := os.Open(path)
if err != nil {
return nil, err
}
defer dir.Close()
// Read the contents of the directory using Readdir
contents, err := dir.Readdir(0)
if err != nil {
return nil, err
}
// Return the contents of the directory
return contents, nil
}
[/code]
|