Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9013131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:11:00+00:00 2026-06-16T03:11:00+00:00

I back up my data to an external drive quite often and have to

  • 0

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.

I’m sure projects of this sort already exist out there, so for me, it is mainly a learning experience.

So to start it off, I have a method that will get all my folders and files so that I can populate my tree:

public static void listAllFiles(String directory, DefaultMutableTreeNode parent, Boolean recursive) {
    File [] children = new File(directory).listFiles(); 

    for (int i = 0; i < children.length; i++) { 
        DefaultMutableTreeNode node = new DefaultMutableTreeNode(children[i].getName());    

        if (children[i].isDirectory() && recursive) { 
            parent.add(node); 
            listAllFiles(children[i].getPath(), node, recursive);    
        } else if (!children[i].isDirectory()){ 
            parent.add(node); 
        }
    }
}

Once the method is called, I simply create my JTree and add it to my view:

myTree = new JTree(parent);
jScrollPane1.setViewportView(myTree);

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?

Edit

By efficient, I mean is least likely to bog down the computer in case the file tree consists of thousands of files.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T03:11:01+00:00Added an answer on June 16, 2026 at 3:11 am

    I think the answer is: Why compare JTree’s? JTree is a GUI element for displaying data – not a data structure for storing/comparing/manipulating data.

    So what you should do is come up with a data structure to compare your data in, and then use the JTree to display the results of your compare. Assuming CPU resources are what you want to conserve, I’d say you want to use a TreeMap.

    Essentially you’d build your TreeMap on the source file system, and then remove items from the TreeMap as you find (and match) them on the destination file system. Once you’re done with the compare, you can display files that still need syncing in a JTree.

    Best of all, since TreeMap guarentees log(n) for the containsKey, get, put and remove methods, it’ll cost you nLog(n) to insert all the files in the source, and nLog(n) to remove (basically your compare) all the keys in the destination.

    Edit

    Oh, and WinMerge is one of the best tools I’ve ever used for file system comparisons. Of course, I’ve never used it for syncing a backup drive…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have an application that parses data from external sources and localizes it back,
I have a problem returning data back to the function I want it returned
I have multiple NSURLConnections running providing data back to the delegate objects. Is it
Possible Duplicate: Xcode: Storyboard Tabbed Application Passing Data Back and Forth Basically I have
I currently have an iPhone app that reads data from an external XML file
I am loading data from external html files within my domain into a div
There is an external server posting data back to my server that is coming
I've read upstream program from here ... http://xunitpatterns.com/Back%20Door%20Manipulation.html If the data store is external
I have a bunch of external forms that post data into databases via CFC's.
If I have a table in Excel, populated via an external data connection, how

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.