How to list files recursively with go-mega

403 views Asked by At

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
}
0

There are 0 answers