You can try using ReadDir in the io/ioutil . In documents:
ReadDir reads a directory named dirname and returns a list of sorted directory entries.
The resulting snippet contains the os.FileInfo types that provide the methods listed below here . Here is a basic example that lists the name of everything in the current directory (folders are included but not specially marked - you can check if the item is a folder using the IsDir() method):
package main import ( "fmt" "io/ioutil" "log" ) func main() { files, err := ioutil.ReadDir("./") if err != nil { log.Fatal(err) } for _, f := range files { fmt.Println(f.Name()) } }
RocketDonkey Feb 03 '13 at 2:29
source share