View Single Post
Join Date: Nov 2007
Posts: 121
Reputation: puneetkay is on a distinguished road 
Solved Threads: 23
puneetkay's Avatar
puneetkay puneetkay is offline Offline
Junior Poster

Re: Recursive File List - Help me problem solve please

 
0
  #6
Jan 10th, 2009
Hello again,

And again its working fine for me.

  1. public static void main(String[] args) {
  2. for(File file : File.listRoots()){ // listRoots() method return list of drives. array of File type.
  3. search(file);
  4. }
  5. }
  6.  
  7. public static void search(File f) {
  8. if ( !f.exists() ) return;
  9. String name = f.getName();
  10. System.out.println(name);
  11. if ( f.isDirectory() ) {
  12. File[] files = f.listFiles();
  13. for( int i = 0 ; i < files.length; i++ ) {
  14. search( files[i] );
  15. }
  16. }
  17. }

Regards,
Puneet Kalra
www.PuneetK.com
Sun Certified Java Programmer


Admin of Pikk - Object Relational Mapping Framework
Reply With Quote