aspose file tools*
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
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to get all the files that have the same extension in a directory