File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes list of files in a directory Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "list of files in a directory" Watch "list of files in a directory" New topic

list of files in a directory

geet kaur
Ranch Hand

Joined: Sep 03, 2008
Posts: 79
guys just confused aboout one thing...when i m using the list() while searching then shouldn't it display all the files in the directory and its subdirectories?
i know its a simple quest but still i am revolving around thid...please help!
Rene Larsen
Ranch Hand

Joined: Oct 12, 2001
Posts: 1179

No you will only see the files and folders inside the filepath you are in.

File API - public String[] list()

An array of strings naming the files and directories in the directory denoted by this abstract pathname. The array will be empty if the directory is empty. Returns null if this abstract pathname does not denote a directory, or if an I/O error occurs.

Regards, Rene Larsen
Dropbox Invite
Rob Spoor

Joined: Oct 27, 2005
Posts: 20279

If you need the files of the sub directories as well you will need to call list() on all the sub directories as well, and on its sub directories, etc.

How To Ask Questions How To Answer Questions
geet kaur
Ranch Hand

Joined: Sep 03, 2008
Posts: 79
thanks guys!!!
I agree. Here's the link:
subject: list of files in a directory
It's not a secret anymore!