File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes I/O and Streams and the fly likes Listing all in a root (39 Line working code) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Listing all in a root (39 Line working code)" Watch "Listing all in a root (39 Line working code)" New topic
Author

Listing all in a root (39 Line working code)

john price
Ranch Hand

Joined: Feb 24, 2011
Posts: 495

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) :


“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” (Mosher's Law of Software Engineering)
“If debugging is the process of removing bugs, then programming must be the process of putting them in.” (Edsger Dijkstra)
Madhan Sundararajan Devaki
Ranch Hand

Joined: Mar 18, 2011
Posts: 312

You may use recursive programming technique, to traverse the entire depth of directory structure.


S.D. MADHAN
Not many get the right opportunity !
john price
Ranch Hand

Joined: Feb 24, 2011
Posts: 495

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

Joined: Mar 18, 2011
Posts: 312

You may need to make the following changes.

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19759
    
  20

And even one more change:


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

And even one more change (everything). Java 7:



"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
john price
Ranch Hand

Joined: Feb 24, 2011
Posts: 495

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
 
subject: Listing all in a root (39 Line working code)