I have a question that might be linguistic agnostic, but for this particular implementation I use Java. It is possible and relatively trivial to list folders in a directory - using this function:
private DefaultMutableTreeNode GenerateFSTree(File f) { int i = 0; File[] Children = f.listFiles(); DefaultMutableTreeNode x = new DefaultMutableTreeNode(f.getName()); if ( Children != null ) { for ( i = 0; i < Children.length; i++ ) { File f_cur = Children[i]; if ( f_cur.isDirectory() && ( this.DisplayHidden || !f_cur.isHidden() ) ) { x.add(GenerateFSTree(f_cur)); } } } return x; }
As you can see, this makes heavy use of recursion to evaluate the file system, and as a result you get the DefaultMutableTreeNode element tree.
Now my question is: is there a faster way to do this? It must be because it's slow. Try doing this on / and it will take forever. However, if I use Nautilus or the built-in Java file selection dialog, the tree will be displayed instantly.
So my question is: how can I speed this up?
thanks
user257111
source share