0

I'm using a third party library to connect to the mega.nz api and can't figure out a good algorithm to list all files in every directory.

GetChildren could be called on "i" again. But if I do it this way i would just get the files which are on the root directory.

import (
    "fmt"
    "github.com/t3rm1n4l/go-mega"
    "path"
)

func returnFileNames (mc *mega.Mega) []string {
    var files []string

    // Get children of
    a, _ := mc.FS.GetChildren(mc.FS.GetRoot())

    for _, i := range a {
        if i.GetType() != 1 { // NodeType is not a Directory
            files = append(files, path.Join("root", i.GetName()))
        } else {
            // ???
        }
    }

    return files
}
Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
Sansch
  • 61
  • 1
  • 5
  • A typical path would be to write a function that took a `*mega.Node` and returned a list of path names in and underneath that directory. When it saw an item where `i.GetType() == mega.FOLDER`, it would call itself. – David Maze Nov 25 '18 at 20:48
  • For ideas, see `filepath.Walk`: https://golang.org/pkg/path/filepath/#Walk – peterSO Nov 25 '18 at 22:36

0 Answers0