How to get list of files in a folder golang?

Member

lue.lemke

by lue.lemke , in category: Golang , 20 days ago

How to get list of files in a folder golang?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by lucile , 20 days ago

@lue.lemke You can use ioutil.ReadDir to get list of files in golang, my example:


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
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()) // filename
   }
}