Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat is an efficient way to compare JTrees?
    text
    copied!<p>I back up my data to an external drive quite often and have to sift through files I have and haven't already transferred over. I thought it would be useful to create a tool that will allow me to select two directories, compare them, and then transfer the files over with a few clicks of a button.</p> <p>I'm sure projects of this sort already exist out there, so for me, it is mainly a learning experience. </p> <p>So to start it off, I have a method that will get all my folders and files so that I can populate my tree:</p> <pre><code>public static void listAllFiles(String directory, DefaultMutableTreeNode parent, Boolean recursive) { File [] children = new File(directory).listFiles(); for (int i = 0; i &lt; children.length; i++) { DefaultMutableTreeNode node = new DefaultMutableTreeNode(children[i].getName()); if (children[i].isDirectory() &amp;&amp; recursive) { parent.add(node); listAllFiles(children[i].getPath(), node, recursive); } else if (!children[i].isDirectory()){ parent.add(node); } } } </code></pre> <p>Once the method is called, I simply create my JTree and add it to my view:</p> <pre><code>myTree = new JTree(parent); jScrollPane1.setViewportView(myTree); </code></pre> <p>So once I have my two JTrees, how would I compare the nodes to see what files don't exist on my external? Would it be easier to just compare the array of files?</p> <p><strong>Edit</strong></p> <p>By efficient, I mean is least likely to bog down the computer in case the file tree consists of thousands of files.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload