• Post Reply Bookmark Topic Watch Topic
  • New Topic

Using FilenameFilter

 
Roshini Sridharan
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

When i use FilenameFilter to filter .txt files, i am not getting the sub folder if any in that directory.. I am trying to list all files with specific extension in the given drive and its sub folders.

It would be helpful if someone could give an idea or sample code to solve this problem.

Thanx in advance.

Regards
Roshini.S
 
Edward Kenworthy
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well that's no surprise unless your directory names end in .txt: try checking whether the filename ends in .txt OR is a directory: File.isDirectory()
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I usually prefer FileFilter to FilenameFilter - less time is wasted converting things to File objects, which are more usefuol than Strings for talking about files. However, to list subdirectory contents too, I think you're probably best off not using File(name)Filter, and just recursively call File's listFiles method:
 
Roshini Sridharan
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Many thanx for the support extended. The code was quiet helpful. Actually i tried out something like that but was taking more time to give out the list. This is quiet fast than what i tried out.

Regards
Roshini.S
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!