aspose file tools*
The moose likes Java in General and the fly likes Getting A File List From A Directory Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Getting A File List From A Directory" Watch "Getting A File List From A Directory" New topic
Author

Getting A File List From A Directory

Alan Jackson
Greenhorn

Joined: Oct 26, 2004
Posts: 26
Okay, here is my problem. I'm trying to develop a small RMI application which will look in the folder "c:/alanistic" and produce an object array called "fileList" which will hold the names of all of the files in the directory. What I have been trying is:

File initialDir = new File("C:/comu303ass1");

public static void listFiles(File pInitialDir) {
File[] fileList = pInitialDir.listFiles();
for (int i = 0; i < files.length; i++) {
String fileName = fileList[i].getName();
}

Basically my app will act as a server, so when a client connects it will list all the files in the clients folder.

Any info is appreciated.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12769
    
    5
If what you want is just the names, why not use the list() method? The only reason I can think of to use listFiles() is so you can apply a FileFilter.
Bill
Michael Herrmann
Ranch Hand

Joined: Dec 06, 2003
Posts: 60
I wrote a little class and got it finished with the help of other form members that might help you(incl. recursively searching through subdirectories of subdirectories of subdirectories of...).
You can find it here

Regards,
Michael Herrmann
[ October 26, 2004: Message edited by: Michael Herrmann ]
 
 
subject: Getting A File List From A Directory