This week's book giveaway is in the HTML Pages with CSS and JavaScript forum.
We're giving away four copies of Testing JavaScript Applications and have Lucas da Costa on-line!
See this thread for details.
Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Using FilenameFilter

 
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
 
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()
 
Wanderer
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
 
It's just a flesh wound! Or a tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic