Enumere todos los archivos, directorios y subdirectorios con el árbol de tomahawk

I've been using tomahawk (1.1.11) for a project. I want to display a tree with all the files and subdirs (and files in those subdirs). I have a code, but it's not listing all of the files and dirs, and don't know where's the mistake.

public TreeNode getTreeData() {
    path = loadConfiguredPath();
    String dependencia = userVerifier.getDependencia();

    if (dependencia.equals("TEST")) {
        path = path + "dataFiles";
    } else {
        path = path + "dataFiles\\" + dependencia;
    }

    dirRoot = new File(path);
    treeRoot = new TreeNodeBase("folder", "BASEDIR", false);
    createTree(dirRoot, treeRoot);

    return treeRoot;
}

private void createTree(File fileRoot, TreeNode treeRoot) {
    File[] files = fileRoot.listFiles();
    TreeNodeBase tnb;
    for (File f : files) {
        if (f.isDirectory()) {
            tnb = new TreeNodeBase("folder", f.getName(), false);
            treeRoot.getChildren().add(tnb);
            createTree(f, tnb);
        }
        if (f.isFile()) {
            tnb = new TreeNodeBase("file", f.getName(), false);
            treeRoot.getChildren().add(tnb);
            //return;
        }
    }
    return;
}

UPDATE: code corrected as mention in comment.

preguntado el 08 de noviembre de 11 a las 18:11

Sorry, finally found my error ! I was returning when just one file was found. and I just change that retorno at the end of the for loop. Thanks anyway. -

1 Respuestas

Sorry, finally found my error !

I was returning when just one file was found. and I just change that retorno at the end of the for loop.

Gracias de cualquier manera

respondido 09 nov., 11:06

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.