I need to create a gui application.. When the user clicks the start button use a JFileChooser to allow them to pick a directory from the system and then run the recursive search of the file system from that directory and display the directory and each file in the JTextArea.

Here is what I have... My problem is that I cant get the directory or files to print in the JTextArea.. Can someone please help me? Here is my action code.
Thanks

public void actionPerformed(ActionEvent evt)
           {
               //which button
               if (evt.getSource() == quitButton)
               {
                   System.exit(0);
               }
            else if (evt.getSource() == openButton)
            {
                //create a filechooser
    JFileChooser chooser = new JFileChooser();
    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    int returnVal = chooser.showOpenDialog(null);
    if(returnVal == JFileChooser.APPROVE_OPTION){
    chooser.getCurrentDirectory();}{
       File dir = new File("");

    File[] children = dir.listFiles();
    if(children == null){
        //either directory does not exit or is not a directory
    }else{
        for (int i=0; i<children.length; i++){
            //get filename of file or directory
            File fileName = children[i];
        }
    }
         
       resultArea.append(chooser.getName());
                }
               }

           }
        }
       //create the inheritance to each button
         FileSearchListener buttListener = new FileSearchListener();
         openButton.addActionListener(buttListener);
         quitButton.addActionListener(buttListener);
    }
}

You have a loop where you get each file name in turn, but you do nothing with them. You know how to append text to your result area, so...


ps: When you post your code, post it properly indented in CODE tags.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.