Click here to Skip to main content
15,891,905 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Ok so this whole Java thing is a still new to me and I am trying to learn it by building myself something to list all the folders and subfolders i have in my music collection (this is a lot)

I have the following code done so far and it loops through and lists the top level repeatly about 10 times for each folder. I had it just doing it one before i changed it.

Could anyone help me correct it and have it listing all folders??

SQL
public static void main(String args[]){
   File file = new File("D:\\music");
   File[] files = file.listFiles();
   for (int fileInList = 0; fileInList < files.length; fileInList++)
   {
         if (file.isDirectory()){

            File[] subFolder = file.listFiles();
            for (int i=0; i< subFolder.length; i++) {
                FoldersOnly(new File(files, subFolder[i]));

   System.out.println(files[fileInList].toString());
   }
       }
    }
}
}



I have been using the interent and books to help me get this far but i just cant get the last bit right. The error seems to be in the FoldersOnly line of code according to Netbeans but I just cant get it to work.
Posted

1 solution

I am not a Java developer though please have a look at these links below, they might help you:

http://www.javabeat.net/tips/19-recursively-traversing-files-and-folders-usin.html[^]
 
Share this answer
 
v2
Comments
Toniyo Jackson 22-Dec-10 1:56am    
Edited the link.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900