Tree-View Просмотр всех каталогов, например, на "C: /" - PullRequest
0 голосов
/ 12 сентября 2018

У меня проблема с просмотром дерева. Я пытаюсь создать дерево для отображения моего диска C: / -. В «FooUtil» я уже начал создавать новые Foos, загружая все файлы в коллекцию (через file.listFiles()). Затем я запускаю Collection и для каждого файла создаю new Foo с родительским «корнем» и fileName. Теперь мой вопрос: вы, ребята, могли бы создать алгоритм для считывания всех файлов (и их подкаталогов !!)? Это мой код прямо сейчас:

    File[] fileCollection = null;

    String[] list = fileFolder.list();
    fileCollection = fileFolder.listFiles();

    ArrayList<File> tempfileList = null;
    ArrayList<File> fileList = null;

    if (fileCollection != null) {
        fileList = Lists.newArrayList(fileCollection);
    } else {
        fileList = Lists.newArrayList();
    }

    final IModel<List<File>> fileListModel = new ListModel<File>(fileList);
    //

    Foo[] fooz = new Foo[fileList.size()];
    int i = 0;
    int x = 0;
    // creating root
    Foo fooRoot = new Foo("root");
    // fooz[0] = new Foo("root");

    for (File file : fileListModel.getObject()) {
        // creating sub-directories in C:/
        fooz[i] = new Foo(fooRoot, file.getName());

        File tempFile = new File(file.getAbsolutePath());
        //
        if (tempFile.listFiles() != null) {
            tempFileCollection = tempFile.listFiles();
            tempfileList = Lists.newArrayList(tempFileCollection);
            Foo[] fooz2 = new Foo[tempfileList.size()];
            x = 0;

            for (File file2 : tempFileCollection) {
                fooz2[x] = new Foo(fooz[i], file2.getName());

             // here i could go for the next subdirectories

                x++;
            }

        }
        //
        i++;
    }
    foosy.add(fooRoot);
    return foosy;
...