• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
kay lin
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic