File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Listing all in a root (39 Line working code)

 
john price
Ranch Hand
Posts: 495
Chrome Java Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have this set up :


It works 100%. But, as the code says, it only goes 2 deep. I need this to be going until it runs out of dir's to check. If it isn't a dir, I want it to stop at that dir and :

Anyway, I was thinking something along the lines of a while() statement. I just don't know how to implement it. If you could provide code or insight that would be great.

Thanks,
cc11rocks

This is what it prints out for my "D:\" drive (in case you were wondering) :
 
Madhan Sundararajan Devaki
Ranch Hand
Posts: 312
Java MS IE
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You may use recursive programming technique, to traverse the entire depth of directory structure.
 
john price
Ranch Hand
Posts: 495
Chrome Java Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about this? :


If you were wondering, yes I came up with all of this myself. No copying
Thanks,
cc11rocks
 
Madhan Sundararajan Devaki
Ranch Hand
Posts: 312
Java MS IE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You may need to make the following changes.

 
Rob Spoor
Sheriff
Pie
Posts: 20381
46
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And even one more change:
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And even one more change (everything). Java 7:


 
john price
Ranch Hand
Posts: 495
Chrome Java Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you guys so much! Just to clarify, you were having the program do the same thing I was, just in a different way (and with less bugs as without "!= null" returns a NullException)?
I am currently using your method. It works 100% (with a slightly modified FileTest()).

In case you are wondering, I went through my whole hard drive. The file that I saved all the information in took up 13.5 MB of space. My CPU was going crazy. I had very little memory left.
Thank you guys again,
cc11rocks
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic