How do I get a list of directories and sub-directories?

Hi All,
I'm new to Java and have a couple of questions that are really stumping me and I sure could use some help.
Question 1:
I have this class file that I want to return back me a list of directories and only directories, not files. I can't figure out how to do this. I know I need to use the isDirectory() function but I can't figure out how to use it. The class file currently is returning back both directories and files. Please help!
Question 2:
Once I get the list of directories, I need to also get a listing of all subdirectories to form a directory tree starting at my File dir value (example: C:\Windows) in the constructor. Any ideas?
Thanks
import java.io.*;
public class DirList {
     private String list = "";
     public DirList(File dir){
          File f = new File(dir.toString());
          String[] files = f.list();
          for ( int i=0;i<files.length; i++ ){
               list += files[i] + "\n";
          }  // end for
     }  // end constructor
     public String getList(){
          return list;     
     }  // end method getList
}  // end class DirList

I'm not familiar of the recursion technique that you speek of. If
this would work, please share it with me.Okay, i'll try, I assume that you don't care what level a subfolder is right! With a selected folder (from fileChooser), you want to obtain a list of all subfolders.
After you have select a folder from the filechooser
import java.io.File;
import java.util.ArrayList;
public class AllSubFolders
  private static ArrayList allSubFolders = new ArrayList();
  public static void main(String [] args) {
    File selectedFolder = ....; //a folder seleted from the filechooser
    getSubFolder(selectedFolder );
  public static void getSubFolder(File aFolder) {
    File[] file = aFolder.listFiles();
    for (int n = 0; n < file.length; n++) {
      if (file[n].isDirectory()){
     allSubFolders.add(file[n]);
     System.out.println(file[n].getAbsolutePath());
     getSubFolder(file[n]); //recursion method call
}You can see that getSubFolder() method call it self, it will do right down to the end of the tree, try it out by replacing the line
File selectedFolder = ....; to
File selectedFolder = new File("c:\\yourFolder\\");

Similar Messages

  • How can I get a list of apps which are supported on ipod touch model ma623zo?

    How can I get a list of apps which are supported on ipod touch model ma623zo?
    It's about 6 years old I think.
    I have put the latest IOS on there (currently 3.1.3 (7E18)).
    I download apps from the app store but they often fail to launch. I assume they're incompatible.
    Is there a way to check which apps will work and which won't before I buy them?
    Thanks!

    I have no idea how my reply could be "misleading". I stated the exact situation: there are millions of apps in the iTunes Store, and providing a comprehensive, accurate list of which apps support which version(s) of iOS would be highly impractical. You can perhaps help with your search by going to AppShopper:
    http://appshopper.com/search/?search=iOS+3
    That will give you at least some starting points, but AppShopper is neither comprehensive nor completely accurate. I've found a number of apps listed there over the time the site has existed that either are no longer offered or which have been updated beyond the iOS version indicated. But it might help.
    Regards.

  • How do i get a list of all the apps i have purchased this year

    how do i get a list of all the apps  have purchased this year and how much each app was

    Check your iTunes purchase history (click your email address in the upper right corner in the iTunes App Store-> log in -> click Purchase History).  This gives you a comprehensive list of apps you've purchased.
     Cheers, Tom

  • How can I get a list of database names from environment

    Hi,
    How can I get a list of database names from environment.
    I had found a method in JE API Docs named Environment.getDatabaseNames(), and i couldn't found the same method in Berkeley DB.
    I use java interface, is it supported?
    Thanks.

    Hello,
    I don't know if it would work for you, but have you checked the db_archive utility at:
    http://download.oracle.com/docs/cd/E17076_01/html/api_reference/C/db_archive.html
    Check the -s option.
    Thanks,
    Sandra

  • How do I get a list of current activations for my license?

    We have a company license which we use for multiple installs.  Over time, we have replaced and/or reimaged PCs and reinstalled and activated the software.  We just started getting a warning that license have been exceeded.  We were unaware it needed to be deactivated on decommissioned machines.  How do we get a list of activated machines and reconcile that with the machines which have had it removed or been reimaged and activated again?

    Hi,
    There is not tool available for external use to keep check of your activations.
    You have to manually keep track or you may contact customer service to check activation count on product.
    Regards,
    Ajlan Huda.

  • How do i get a list of all Roles defubed under a particular OrganizationalUnit? How can i use LDAPConnection.search method for this?

     

    Sorry for the typographical mistake.
    Please read the question as:"How do i get a list of all Roles defined under a particular OrganizationalUnit? How can i use LDAPConnection.search method for this?"

  • HT1420 how can I get a list of the computers that are currently authorized?

    I need to authorize my home computer after switching from PC to Mac. How can I get a list of which devices are currently authorized?

    There is no list.

  • Hi ,How can I get a list of all laptops or users with folder direction enabled or offline files enabled, be it sccm or poerwshell . i have struggled for a week.

    Hi ,how can I get a list of all laptops or users with folder direction enabled or offline files enabled, be it sccm
    or poerwshell . i have struggled for a week
    tchocr

    Hi,
    There is no such PowerShell command can achiev this. Maybe you can use a script to get the user name with folder redirection enabled. However, I am not familiar with writing script, and it would be better for you to ask in script forum below for professional
    assistance:
    http://social.technet.microsoft.com/Forums/en-US/home?forum=ITCG&filter=alltypes&sort=lastpostdesc
    Best Regards,
    Mandy
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact [email protected]

  • How can I get a list of active users on an AS Java platform on a cluster?

    Hello Experts,
    I have an AS Java NetWeaver CE v7.1 EhP1 SP3 system and it's running in a cluster.  Do you know how I can get a list of all users that are currently logged in or whom have active sessions on each application server instance?
    Thanks,
    Sam

    > I don't know how to get classes used by VA for this tab.
    I wouldn't make any development investments based on classes for the VA anymore...
    Considering that not only Salvatore himself, but also the JControl might decide for itself that the system needs a hard shutdown and restart.. a possibly better solution would be to use a redirect. If the message server does does not respond or does not find any DIs or not the one which your previous session state was for, then redirect to a page with a meaningfulll message (and apology on it.
    Just a thought,
    Cheers,
    Julius

  • How can I get a list of purchased apps?

    Recently restored my iPhone from backup, and I need to download my apps.  How can I get a list of apps that I've downloaded/purchased?
    If I search for an app via the app store that I had previously installed, the Install icon turns into a Cloud with a down arrow symbol on it - there must be a way to get a list of all of these right?
    Anyone clever enough to solve this riddle?

    Open the App Store app, go to the Updates pane and tap Purchased.

  • How can I get a list of all workbooks

    Can anybody please tell me how can I get a list of all my workbooks that are on my Oracle Discoverer database without having to manually write them down? I am using Oracle Database 10g Enterprise Edition.

    Hi,
    To implement the EUL Management BA follow metalink NOTE:556932.1
    there are very simple steps you need to perform in order to use it

  • How can I get a list of all my annotations to send to someone else, listed by PAGE #, not order.

    How can I get a list of all my annotations to send to someone else, listed by PAGE #, not order??

    The comments list is sorted by page by default. If it's not for some reason, click the "Sort comments" button and select that option. It looks like this:

  • How can I get a list of all laptops or users with folder direction enabled or offline files enabled, be it sccm or poerwshell . i have struggled for a week.

    How can I get a list of all laptops or users with folder direction enabled or offline files enabled, be it sccm or poerwshell . i have struggled for a week.

    Hi,
    There is no such PowerShell command can achiev this. Maybe you can use a script to get the user name with folder redirection enabled. However, I am not familiar with writing script, and it would be better for you to ask in script forum below for professional
    assistance:
    http://social.technet.microsoft.com/Forums/en-US/home?forum=ITCG&filter=alltypes&sort=lastpostdesc
    Best Regards,
    Mandy
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact [email protected]

  • HT201269 hi i need help, i just go a new iPhone 5 and i want to put all my backed up stuff on, but it doesn't show on the list, how do i get all my stuff back and yes i did backup the old phone

    hi i need help, i just go a new iPhone 5 and i want to put all my backed up stuff on, but it doesn't show on the list, how do i get all my stuff back and yes i did backup the old phone

    Follow the explicit instructions in the article from which the thread was started and restore the device from the backup of the previous device.

  • How do you get a list of your contacts nick names and their phone numbers on line and print them out?

    How do you get a list of your contacts nick names and their phone numbers on line and print them out?  I've been trying to figure out how to get the list to print out but I can't even find a complete list to view on Verizon's web site.  Does anyone know how to do this?

    Log into your online account. In the, 'I want to', box type, Manage Contacts.
    Place your cursor over any contact, a pop screen will appear with the option to print your contacts

Maybe you are looking for

  • Problem in creating a request

    Hi Friends, I want to transport a table to the production, How can I create a request to that table, I am unable to create a request for that table. Thanx in advance, Line

  • Links to the BBC News Player don't start video streams.

    On the BBC News website there are numerous links to video news streams which should start playing in the BBC News Player (a new popup windows with either web content and a video stream in either Windows Media Player or Real Player format). Whenever I

  • Deletion flags for equipment BOM

    Hi, In equipment BOM header , there are 2 fields for deletion flag : -one is set manually (the one on the right) -the other set by the system (the one on the left). Can someone explain to me how deletion flag indicator (on the left) work? Thanks, P.

  • IPhoto and Adobe Elements 8

    Hi, I want to migrate my Elements 8 (Windows XP)databas to iPhoto. Is that possible? Without new indexing (24000 Photos). THX for respons. Michael

  • The application (all adobe applications) has unexpectedly quit

    Hello everyone, I have a problem with my Adobe Cs3 Design Premium package. I don't know if i have the correct forum section. I now managed to install this software correctly on mac osx but when i try to start one of the application they will all give