This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes how to get all the files that have the same extension in a directory Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "how to get all the files that have the same extension in a directory" Watch "how to get all the files that have the same extension in a directory" New topic
Author

how to get all the files that have the same extension in a directory

kay lin
Ranch Hand

Joined: May 20, 2004
Posts: 132
Hi all:
I am just wondering, is there any API function I can call that would return me an array/enumeration of all the files in this directory as well as the sub directory that has the same extension

for example

I am in C:\test directory,

I would like to have a list of files that ends in .xml in the C:\test directory as well as its subdirectory.

Please let me know

Many thanks...
Elihu Smails
Ranch Hand

Joined: Jan 12, 2005
Posts: 37
check out java.io.File and java.io.FileFilter. You must create a FileFilter and pass it in to the File.listFiles method. This will give you your listing of the files that you want.
Michael Herrmann
Ranch Hand

Joined: Dec 06, 2003
Posts: 60
The FileIterator I wrote might help you if you need to search subdirectories as well. If not, File#listFiles(FilenameFilter filter) is the better choice.

Regards,
Michael Herrmann
 
Consider Paul's rocket mass heater.
 
subject: how to get all the files that have the same extension in a directory
 
Similar Threads
Setting up JAVA
How to use the FilenameFilter interface
Executing files....mp3 style
What name to use to save files; what classes are allowed?
PATH & CLASSPATH?