V
V
v- death2015-12-10 20:24:46
go
v- death, 2015-12-10 20:24:46

How to find all directories and files?

Hi. For example, I have a directory

/home/v-smerti/localhost/api/src/public/file_server/js/new

I need to get a list of all directories and files and build an array of the form from this
/home/v-smerti/localhost/api/src/public/file_server/js/new : {
 "test" : [alert.js, gg.js ],
 "index" : [views.js, start.js]
}

Of course, I can cycle for a long time and very successfully, but in any case, someone already did something like this 100%
Thanks in advance for the copy-paste / link

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey K, 2015-12-10
@vGrabko99

https://golang.org/pkg/io/ioutil/#ReadDir

dirs, err := ioutil.ReadDir(config.ProjectDir)
  if err != nil {
    log.Fatal(err)
  }

for _, dir := range dirs {
  fmt.Print(dir.Name())
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question