A
A
ajlhimik2018-05-05 22:04:35
go
ajlhimik, 2018-05-05 22:04:35

How to get folder list from folders in go?

package main

import (
    "fmt"
    "io/ioutil"
    "log"
)

func main() {
    files, err := ioutil.ReadDir(".")
    if err != nil {
        log.Fatal(err)
    }

    for _, file := range files {
        fmt.Println(file.Name(), file.IsDir())
        if file.IsDir() == true {
            files2 := ioutil.ReadDir("./"+file.Name())
            for _, file2 := range files2 {
                fmt.Println(file2.Name())
            }
        }
    }
}

error: .\dir.go:18:37: multiple-value ioutil.ReadDir() in single-value context,
as I understand it, ReadDir can only be used in 1 variable
and what to do if it doesn’t get confused

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
Leshiy Urban, 2018-05-05
@ajlhimik

Everything is simpler: you checked for an error in the line, but forgot

P
Papa, 2018-05-06
Stifflera @PapaStifflera

and what if it doesn't freeze

write in 1C

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question