It's not a secret anymore!
The moose likes Performance and the fly likes Listing Directory contents Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Performance
Reply Bookmark "Listing Directory contents" Watch "Listing Directory contents" New topic
Author

Listing Directory contents

V Bose
Ranch Hand

Joined: Jul 10, 2003
Posts: 113
Is there a way I can iterate through the contents of a directory without having to use listFiles ?

I am trying to avoid having to store the file names in memory, if there is going to be just way too many files...
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18670
Not using current standard Java libraries. Check out RFE 4285834. Too bad. I think your best bet at this point is, if you can afford to give up cross-platform compatibility (or if you can put in extra work to make it work on other platforms on a case-by-case basis), use Runtime.getRuntime().exec() to exec a simple script to list the files in a directory and put those names in a text file. (In Unix this could be as simple as "ls -1 [directory_path] > [output_file_name]". Then you can read the file one line at a time and do whatever you want with each file name. Or, you could use JNI instead. Hope that helps...


"I'm not back." - Bill Harding, Twister
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Listing Directory contents
 
Similar Threads
How to browse the contents of an LDAP directory using the API?
Unsorted file list
Copying Directories
deleting directory
Uploading a directory using JSP/JSF