Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-26-2007, 03:45 PM
Member
 
Join Date: Nov 2007
Posts: 2
nimraj is on a distinguished road
How do you recursively traverse through file folders ?
Hello all,
How do you recursively traverse through file folders ?
Or is there any other way to traverse through windows directory structure and bring it into a data structure ?

Any help is appreciated.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 11-26-2007, 06:58 PM
Senior Member
 
Join Date: Jul 2007
Posts: 1,022
hardwired is on a distinguished road
Code:
import java.io.File; import java.util.*; public class GatheringFiles { public static void main(String[] args) { File folder = new File("."); List<File> list = new ArrayList<File>(); getFiles(folder, list); System.out.println("list.size = " + list.size()); } private static void getFiles(File folder, List<File> list) { folder.setReadOnly(); File[] files = folder.listFiles(); for(int j = 0; j < files.length; j++) { list.add(files[j]); if(files[j].isDirectory()) getFiles(files[j], list); } } }
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 11-27-2007, 02:45 PM
Member
 
Join Date: Nov 2007
Posts: 2
nimraj is on a distinguished road
Thanks
thanks hardwired, for the quick and accurate reply.
This is pretty good, exactly what i needed.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
recursively searching through arraylists newtojava7 New To Java 1 03-17-2008 03:36 AM
Computing Fibonacci numbers recursively Java Tip Java Tips 0 01-22-2008 09:20 PM
can java.io.File create a list of all files and folders. MattStone New To Java 20 12-17-2007 04:20 PM
error with traverse a relations ship darkbalder Enterprise JavaBeans 0 12-11-2007 06:25 PM
URGENTTT...zip folders in java rach New To Java 3 08-13-2007 04:55 PM


All times are GMT +3. The time now is 04:27 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org